{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Userdata\Shared\Logs\IntegrationSD\log_data.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res} 1 Jun 2021, 16:28:17
{txt}
{com}. 
. 
. /////////////
> ///YEAR 2010
> /////////////
> 
. *import election results 
. import excel "D:\Data\ExtData\ValResData\Riksdagsvalet_2010\VDValRes_2010", firstrow clear
{res}{txt}
{com}. 
. ///District-variable with leading zero to match with other election-data
> gen str4 z = string(VALDIST,"%04.0f")
{txt}
{com}. gen str2 ll = string(LAN,"%02.0f")
{txt}
{com}. gen str2 kk = string(KOM,"%02.0f")
{txt}
{com}. 
. 
. egen llkkdddd = concat(ll kk z)
{txt}
{com}. destring llkkddd, replace
{txt}llkkdddd: all characters numeric; {res}replaced {txt}as {res}long
{txt}
{com}. 
. ///Create an *other* category
> gen all = Mtal+Ctal+FPtal+KDtal+FItal+MPtal+PPtal+Stal+SDtal+Vtal
{txt}
{com}. gen other = Rostande-all
{txt}
{com}. 
. ///Remove district called "onsdagsdistrikt" - foreign votes and postal votes
> encode VALDISTRIKT, gen(vald_nmr)
{txt}
{com}. 
. /*3485 are onsdagsdistrikt*/
. drop if vald_nmr==3485
{txt}(395 observations deleted)

{com}. 
. *duplicates report llkkdddd /*OK*/
. 
. drop LAN KOM z kk ll all SPItal SPIproc OVRtal OVRproc OGtal OGproc
{txt}
{com}. 
. ///5668 districts left
> save "E:\ProjData\IntegrationSD\temp\2010_electionresults.dta", replace
{txt}file E:\ProjData\IntegrationSD\temp\2010_electionresults.dta saved

{com}. 
. 
. //////////////
> ///YEAR 2014
> //////////////
> 
. 
. clear all
{res}{txt}
{com}. 
. ///First: want to add number of legitimate votes
> import excel "D:\Data\ExtData\ValResData\Riksdagsval_2014\allmanna-val-2014-huvudresultat-distrikt.xlsx", sheet("Riksdag") firstrow clear
{res}{txt}
{com}. 
. keep Valdistriktskod varavblankavalsedlar Antalröstande Antalogiltigavalsedlar Antalgiltigavalsedlar
{txt}
{com}. rename Valdistriktskod llkkdddd
{res}{txt}
{com}. rename varavblankavalsedlar BLtal
{res}{txt}
{com}. gen BLproc = (BLtal/Antalröstande)*100
{txt}
{com}. 
. duplicates tag llkkdddd, gen(tag)

{p 0 4}{txt}Duplicates in terms of {res} llkkdddd{p_end}
{txt}
{com}. 
. save "E:\ProjData\IntegrationSD\temp\2014_electionresults_tempfile.dta", replace
{txt}(note: file E:\ProjData\IntegrationSD\temp\2014_electionresults_tempfile.dta not found)
file E:\ProjData\IntegrationSD\temp\2014_electionresults_tempfile.dta saved

{com}. 
. 
. ///NOW THE MAIN FILE: 
> use "D:\Data\ExtData\ValResData\Riksdagsval_2014\R_valdistrikt_2014"
{txt}
{com}. 
. ///drop onsdagsdistrikt
> 
. encode dist_type, gen(dist)
{txt}
{com}. drop if dist==1
{txt}(4,765 observations deleted)

{com}. 
. drop dist_type muni_code dist dist_name dist_borders party_votes_prev party_personalvotes
{txt}
{com}. 
. gen str8 llkkdddd = string(dist_code,"%08.0f")
{txt}
{com}. drop dist_code
{txt}
{com}. 
. ///wide format
> 
. reshape wide party_votes, i(llkkdddd) j(party_abb) string
{txt}(note: j = 0020 0675 1146 1170 1177 1195 1270 C DPNS DjuP Däp EAP ENH FI FP Gup HumDe KD KLP KrVP LBPO M MP PP RNP RS S SD SKP SKÅ SPI SVP V VägV)

Data{col 36}long{col 43}->{col 48}wide
{hline 77}
Number of obs.                 {res}   76638   {txt}->{res}    5837
{txt}Number of variables            {res}       4   {txt}->{res}      36
{txt}j variable (34 values)        {res}party_abb   {txt}->   (dropped)
xij variables:
                            {res}party_votes   {txt}->   {res}party_votes0020 party_votes0675 ... party_votesVägV
{txt}{hline 77}

{com}. 
. keep party_votesC party_votesFI party_votesFP party_votesKD ///
> party_votesM party_votesMP party_votesPP party_votesS ///
> party_votesSD party_votesV dist_votes llkkdddd   
{txt}
{com}. 
. ///*other* votes
> foreach y in party_votesC party_votesFI party_votesFP party_votesKD ///
> party_votesM party_votesMP party_votesPP party_votesS party_votesSD party_votesV {c -(}
{txt}  2{com}. replace `y'=0 if `y'==.
{txt}  3{com}. {c )-}
{txt}(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(67 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)

{com}. gen all = party_votesC+party_votesFI+party_votesFP+party_votesKD+party_votesM+party_votesMP+party_votesPP+party_votesS+party_votesSD+party_votesV
{txt}
{com}. gen other = dist_votes-all
{txt}
{com}. drop all
{txt}
{com}. 
. ///generate variables so they are similar to 2010 data
> rename party_votesM Mtal 
{res}{txt}
{com}. gen Mproc = Mtal/dist_votes
{txt}
{com}. rename party_votesC Ctal 
{res}{txt}
{com}. gen Cproc = Ctal/dist_votes 
{txt}
{com}. rename party_votesFP FPtal 
{res}{txt}
{com}. gen FPproc= FPtal/dist_votes 
{txt}
{com}. rename party_votesKD KDtal 
{res}{txt}
{com}. gen KDproc= KDtal/dist_votes 
{txt}
{com}. rename party_votesS Stal 
{res}{txt}
{com}. gen Sproc = Stal/dist_votes 
{txt}
{com}. rename party_votesV Vtal 
{res}{txt}
{com}. gen Vproc = Vtal/dist_votes 
{txt}
{com}. rename party_votesMP MPtal 
{res}{txt}
{com}. gen MPproc = MPtal/dist_votes 
{txt}
{com}. rename party_votesSD SDtal 
{res}{txt}
{com}. gen SDproc= SDtal/dist_votes 
{txt}
{com}. rename party_votesFI FItal 
{res}{txt}
{com}. gen FIproc = FItal/dist_votes 
{txt}
{com}. rename party_votesPP PPtal 
{res}{txt}
{com}. gen PPproc = PPtal/dist_votes 
{txt}
{com}. rename dist_votes Rostande
{res}{txt}
{com}. 
. ///5837 districts
> 
. merge 1:m llkkdddd using "E:\ProjData\IntegrationSD\temp\2014_electionresults_tempfile.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}             390
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}             390{txt}  (_merge==2)

{col 5}matched{col 30}{res}           5,837{txt}  (_merge==3)
{col 5}{hline 41}

{com}. keep if _merge==3
{txt}(390 observations deleted)

{com}. drop _merge tag
{txt}
{com}. 
. save "E:\ProjData\IntegrationSD\temp\2014_electionresults.dta", replace
{txt}file E:\ProjData\IntegrationSD\temp\2014_electionresults.dta saved

{com}. 
. erase "E:\ProjData\IntegrationSD\temp\2014_electionresults_tempfile.dta"
{txt}
{com}. 
. 
. /////////////////////////
> ////DATA FOR PRECINCT 
> /////////////////////////
> 
. clear all
{res}{txt}
{com}. 
. foreach y in 02 06 10 14 {c -(}
{txt}  2{com}. 
. ///30 million ind. assigned to unique district 2002-2014
> use "D:\SCB_ConPol\Stata\VD\Valdist_AV"
{txt}  3{com}. 
. ///year
> keep if Ar==20`y'
{txt}  4{com}. 
. ///some duplicates - because of recykled personal number. ///
> ///2006: just 3 ind/6 obs, 
> ///2010: just 14 ind/28 obs
> ///2014: just 13 ind/26 obs, so just throw these out for simplicity
> 
. duplicates tag LopNr, gen(tag)
{txt}  5{com}. *tab tag
. drop if tag==1 
{txt}  6{com}. 
. *duplicates report LopNr /*OK*/
. 
. keep LopNr llkkdddd
{txt}  7{com}. 
. ///check amount of districts
> *bysort llkkdddd: gen district = _n
. *count if district==1
.  
. *2006: 7,222,779 ind assigned to 5783 unique districts 
. *2010: 7,516,249 ind assigned to 5669 unique districts
. *2014: 7,784,891 ind assigned to 5837 unique districts
. 
. save "E:\ProjData\IntegrationSD\temp\20`y'_electiondistrictsperperson.dta", replace
{txt}  8{com}. 
. {c )-}
{txt}(22,523,981 observations deleted)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}
{txt}(14 observations deleted)
file E:\ProjData\IntegrationSD\temp\2002_electiondistrictsperperson.dta saved
(22,346,348 observations deleted)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}
{txt}(6 observations deleted)
file E:\ProjData\IntegrationSD\temp\2006_electiondistrictsperperson.dta saved
(22,052,854 observations deleted)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}
{txt}(30 observations deleted)
file E:\ProjData\IntegrationSD\temp\2010_electiondistrictsperperson.dta saved
(21,784,216 observations deleted)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}
{txt}(26 observations deleted)
file E:\ProjData\IntegrationSD\temp\2014_electiondistrictsperperson.dta saved

{com}. 
. 
{txt}end of do-file

{com}. 
. ///2. PREPARE POPULATION WEIGHTS, used for better matching of precincts over time
> //THIS TO TRANSLATE 2006/2010 PRECINCTS INTO 2014 PRECINCTS
. 
. do "C:\Userdata\Shared\Dofiles\DoData\IntegrationSD\merge_precincts"
{txt}
{com}. 
. ****************************************************************
. * Authors: Henrik Andersson & Sirus Dehdari
. * This script creates weights for the translation of 2006/2010
. * precincts into 2014 precincts
. ****************************************************************
. 
. clear all
{res}{txt}
{com}. 
. cd "E:\ProjData\IntegrationSD\"
{res}E:\ProjData\IntegrationSD
{txt}
{com}. 
. 
. * Import raw data:
. import delimited "raw\valdistrikt10_14.csv", delimiter(";") clear
{res}{text}(11 vars, 835,826 obs)

{com}. 
. * Replacing comma as decimal:
. destring totbef, replace dpcomma
{txt}totbef: all characters numeric; {res}replaced {txt}as {res}int
{txt}
{com}. destring area_geo, replace dpcomma
{txt}area_geo: all characters numeric; {res}replaced {txt}as {res}double
{txt}
{com}. 
. * The precinct codes are numeric, which means that "0" disappears. We
. * instead transform to string and add "0" to some codes:
. foreach var of varlist lkfv vd{c -(}
{txt}  2{com}. tostring `var', replace
{txt}  3{com}. replace `var' = "0" + `var' if strlen(`var') < 8
{txt}  4{com}. {c )-}
{txt}lkfv was {res:long} now {res:str8}
(272,990 real changes made)
vd was {res:long} now {res:str8}
(272,990 real changes made)

{com}. 
. * A area_geo equal to 0.01 means that a population square has not been divided.
. * We multiply this variable by 100 to get proper shares:
. replace area_geo = area_geo * 100
{txt}(834,541 real changes made)

{com}. replace area_geo = 1 if area_geo > 1
{txt}(573,931 real changes made)

{com}. 
. * We multiply the population square shares by the square total population:
. replace totbef = area_geo*totbef
{txt}variable {bf}totbef{sf} was {bf}{res}int{sf}{txt} now {bf}{res}float{sf}
{txt}(199,777 real changes made)

{com}. 
. * We collapse square population on 2010 and 2014 precinct combinations:
. collapse (sum) totbef, by(vd lkfv)
{txt}
{com}. 
. save temp\vd_2010_2014, replace
{txt}file temp\vd_2010_2014.dta saved

{com}. 
. * Next, we collapse on only 2010 precincts.
. collapse (sum) totbef, by(lkfv)
{txt}
{com}. 
. rename totbef whole_pop
{res}{txt}
{com}. 
. * We merge the data on total population for each 2010 precinct with the
. * data on population in each 2010/2014 precinct combinations.
. merge 1:m lkfv using temp\vd_2010_2014
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}           8,097{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _merge
{txt}
{com}. 
. * By dividing the population for each precinct combination with the total 
. * population of each 2010 precinct, we compute how much of each combination,
. * in terms of 2010 precincts, correspond to 2014 precincts.
. gen share = totbef/whole_pop
{txt}
{com}. 
. rename lkfv precinct2010
{res}{txt}
{com}. rename vd precinct2014
{res}{txt}
{com}. 
. save temp\vd_2010_2014_shares, replace
{txt}file temp\vd_2010_2014_shares.dta saved

{com}. 
. 
. 
. *** The following code does the same thing as above, but for 2006/2014:
. import delimited E:\ProjData\IntegrationSD\raw\valdistrikt06_14.csv, delimiter(";") clear
{res}{text}(10 vars, 885,165 obs)

{com}. 
. destring totbef, replace dpcomma
{txt}totbef: all characters numeric; {res}replaced {txt}as {res}int
{txt}
{com}. destring area_geo, replace dpcomma
{txt}area_geo: all characters numeric; {res}replaced {txt}as {res}double
{txt}
{com}. foreach var of varlist lkfv vd{c -(}
{txt}  2{com}. tostring `var', replace
{txt}  3{com}. replace `var' = "0" + `var' if strlen(`var') < 8
{txt}  4{com}. {c )-}
{txt}lkfv was {res:long} now {res:str8}
(290,562 real changes made)
vd was {res:long} now {res:str8}
(290,587 real changes made)

{com}. replace area_geo = area_geo * 100
{txt}(866,564 real changes made)

{com}. replace area_geo = 1 if area_geo > 1
{txt}(562,223 real changes made)

{com}. 
. replace totbef = area_geo*totbef
{txt}variable {bf}totbef{sf} was {bf}{res}int{sf}{txt} now {bf}{res}float{sf}
{txt}(257,425 real changes made)

{com}. collapse (sum) totbef, by(vd lkfv)
{txt}
{com}. save temp\vd_2006_2014, replace
{txt}file temp\vd_2006_2014.dta saved

{com}. 
. collapse (sum) totbef, by(lkfv)
{txt}
{com}. rename totbef whole_pop
{res}{txt}
{com}. merge 1:m lkfv using temp\vd_2006_2014
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}          21,867{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _merge
{txt}
{com}. 
. gen share = totbef/whole_pop
{txt}
{com}. rename lkfv precinct2006
{res}{txt}
{com}. rename vd precinct2014
{res}{txt}
{com}. save temp\vd_2006_2014_shares, replace
{txt}file temp\vd_2006_2014_shares.dta saved

{com}. 
.  
. 
{txt}end of do-file

{com}. 
. 
. ///3. USE MATCHED INDIVVDUAL/WORKPLACE DATA TO CREATE A VARIABLE FOR NUMBER 
> * AND SHARE OF IM-COLLEAGUES (treatment variable)
. * ALSO CREATES ALL OTHER RELEVANT MEASURES RELATED TO WORKPLACES
. 
. do "C:\Userdata\Shared\Dofiles\DoData\IntegrationSD\Workplacedata"  
{txt}
{com}. 
. *********************
. * Authors: Henrik Andersson & Sirus Dehdari
. * this do-file uses matched individual/workplace data
. * and prepares the individual share of foreign born coworkers as well 
. * as other measures at the worklace level.
. * It generates three files (one for 2006, 2010 and 2014) with all individuals 
. * who are connected to a workplace, and their respecitve share of foreign born 
. * at the workplace. This do-file hence takes out the basic info for the treatment 
. * variable, which will be collapsed at the precinct level at next stage. 
. *********************
. 
. clear all
{res}{txt}
{com}. set more off
{txt}
{com}. 
. cd "D:\SCB_ConPol\Stata"
{res}D:\SCB_ConPol\Stata
{txt}
{com}. 
. ///Before start: socioeconomic data includes variables with nonlinear time addition 
> ///to variable name - change and save temp file before loop
> 
. use "LISA\LISA_2006"
{txt}
{com}. rename AstSNI2002 AstSNI
{res}{txt}
{com}. save  "E:\ProjData\IntegrationSD\temp\LISA2006.dta", replace
{txt}(note: file E:\ProjData\IntegrationSD\temp\LISA2006.dta not found)
file E:\ProjData\IntegrationSD\temp\LISA2006.dta saved

{com}. use "LISA\LISA_2010"
{txt}
{com}. rename AstSNI2007 AstSNI
{res}{txt}
{com}. save  "E:\ProjData\IntegrationSD\temp\LISA2010.dta", replace
{txt}(note: file E:\ProjData\IntegrationSD\temp\LISA2010.dta not found)
file E:\ProjData\IntegrationSD\temp\LISA2010.dta saved

{com}. 
. *2014: must add SSYK data from key prepared before
. use "LISA\LISA_2014"
{txt}
{com}. rename AstSNI2007 AstSNI
{res}{txt}
{com}. 
. merge m:1 ssyk4_2012 using "E:\ProjData\IntegrationSD\raw\nyckelssyk12_96"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       4,792,655
{txt}{col 9}from master{col 30}{res}       4,792,655{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,272,667{txt}  (_merge==3)
{col 5}{hline 41}

{com}. rename SSYK96 SSYK4_96
{res}{txt}
{com}. drop _merge
{txt}
{com}. save  "E:\ProjData\IntegrationSD\temp\LISA2014.dta", replace
{txt}(note: file E:\ProjData\IntegrationSD\temp\LISA2014.dta not found)
file E:\ProjData\IntegrationSD\temp\LISA2014.dta saved

{com}. 
. 
. 
. *WORKPLACE DATA FOR 2006, 2010 AND 2014
. forvalues y = 2006(4)2014 {c -(}
{txt}  2{com}. 
. use "E:\ProjData\IntegrationSD\temp\LISA`y'.dta"
{txt}  3{com}. 
. 
. 
. ///first: only interested in those actually working at a workplace
> ///therefore drop unemployed and self-employed
> ///and those not connected to a workplace
> 
. keep if Yrkstalln==2 
{txt}  4{com}. drop if ArbstId==.
{txt}  5{com}. 
. 
. ///throw out duplicates
> duplicates tag LopNr, gen(tag)
{txt}  6{com}. tab tag
{txt}  7{com}. drop if tag==1
{txt}  8{com}. *2006: none
. *2010: 2 ind/4 obs deleted*
. *2014: 2 ind/4 obs deleted*
. drop tag
{txt}  9{com}. 
. 
. ///ADD Birth country data, need to define foreign born/non-European
> merge 1:1 LopNr using "RTB\FodelselandIFAUGrupp"
{txt} 10{com}.         keep if _merge==3 
{txt} 11{com}.         drop _merge
{txt} 12{com}.         
.         
. ///merge with migration data - used for describing years in country
> merge 1:m LopNr using "RTB\migrationer"
{txt} 13{com}. *drop those in migration data but not in master
. drop if _merge==2
{txt} 14{com}. *duplicates will remain 
. *Generate year, month of arrival - throw out all observations before year in question 
. 
. tostring Datum, replace
{txt} 15{com}. gen im_year = substr(Datum, 1, 4) 
{txt} 16{com}. destring im_year, replace
{txt} 17{com}. 
. gen im_month = substr(Datum, 5, 2) 
{txt} 18{com}. destring im_month, replace
{txt} 19{com}. 
. duplicates drop LopNr if IFAUkod==0, force
{txt} 20{com}. 
. *now sort on im year, duplicates drop takes out all but first obs, 
. *which means that it takes out all but first im year
. 
. ////DUBBELKOLLA SÅ ATT DU INTE FÅR MED KONSTIGA SOM UTVANDRAR FÖRST
> sort LopNr im_year
{txt} 21{com}. duplicates drop LopNr, force
{txt} 22{com}. 
.         *duplicates report LopNr /* OK*/
.         
. 
. ///ADD AGE AND SEX
> ///merge with migration data
> drop _merge
{txt} 23{com}. merge 1:m LopNr using "RTB\Fodelseuppg", keepusing(LopNr FodArMan Kon)
{txt} 24{com}. keep if _merge==3
{txt} 25{com}. drop _merge
{txt} 26{com}. 
. *Birth year
. tostring FodArMan, replace
{txt} 27{com}. gen birth_year = substr(FodArMan, 1, 4) 
{txt} 28{com}. destring birth_year, replace
{txt} 29{com}. 
. gen age = `y'-birth_year
{txt} 30{com}. 
. 
. ////////////////////////////////////////////
> ////NOW THE FOLLOWING LINE OF CODES CREATES 
> ///THE MAIN TREATMENT; SHARE OF IM 
> //// COWORKERS AMONG SWEDED
> ////////////////////////////////////////////    
> 
. 
. ///Start by defining being a native or comming from certain region
> gen swedish = 1 if IFAUkod==0
{txt} 31{com}. gen nordic = 1 if IFAUkod==26 | IFAUkod==27 | IFAUkod==28
{txt} 32{com}. gen western = 1 if IFAUkod == 32 | IFAUkod == 33 | IFAUkod == 34 | IFAUkod == 38 | IFAUkod == 39
{txt} 33{com}. gen europe_other = 1 if IFAUkod == 29 | IFAUkod == 30 | IFAUkod == 31 | IFAUkod == 35 | IFAUkod == 36 | IFAUkod == 37
{txt} 34{com}. gen other =  1 if IFAUkod >39 & IFAUkod < 54
{txt} 35{com}. gen latinamerica = 1 if IFAUkod==40 | IFAUkod==41 | IFAUkod==42
{txt} 36{com}. gen mena = 1 if IFAUkod==44 | IFAUkod==46 | IFAUkod==47 | IFAUkod==48
{txt} 37{com}. gen asia = 1 if IFAUkod==49 | IFAUkod==50 | IFAUkod==51
{txt} 38{com}. gen africa = 1 if IFAUkod==43 | IFAUkod==45
{txt} 39{com}. gen rest_other = 1 if IFAUkod==52 | IFAUkod==53
{txt} 40{com}. 
. ///Now workplace codes, by workplace (ArbstId) , to gen # im coworkers vs # coworkers per workplace
> *all workers at a workplace
. bysort ArbstId: gen coworkers = _N
{txt} 41{com}. 
. *all non-European workers at a workplace
. bysort ArbstId: egen im_coworker = total(other)
{txt} 42{com}. 
. *separated by region
. bysort ArbstId: egen latin_coworker = total(latinamerica)
{txt} 43{com}. bysort ArbstId: egen mena_coworker = total(mena)
{txt} 44{com}. bysort ArbstId: egen asia_coworker = total(asia)
{txt} 45{com}. bysort ArbstId: egen africa_coworker = total(africa)
{txt} 46{com}. bysort ArbstId: egen rest_coworker = total(rest_other)
{txt} 47{com}. bysort ArbstId: egen nordic_coworker = total(nordic)
{txt} 48{com}. bysort ArbstId: egen western_coworker = total(western)
{txt} 49{com}. 
. 
. ///Now that we have created the number of workers at workplace
> * also want to throw out those who are alone
. ///note that since I have thrown out self-employed, this may sometimes be 1 employed plus the boss
> 
. drop if coworkers==1
{txt} 50{com}. 
. ///now condition the created workplace variables on the worker being swedish
> *this creates the main treatment variable, share of (im)coworkers if you are born in Sweden
. foreach x in im latin mena asia africa rest nordic western {c -(}
{txt} 51{com}. gen share_`x'_cworker = `x'_coworker/coworkers
{txt} 52{com}. gen share_`x'_cworker_swe = share_`x'_cworker if IFAUkod==0
{txt} 53{com}. gen `x'_coworker_swe = `x'_coworker if IFAUkod==0
{txt} 54{com}. {c )-}
{txt} 55{com}. 
. *Total coworkers if you are swedish
. gen coworkers_swe = coworkers if IFAUkod==0
{txt} 56{com}. 
. *to create "CO"-workers, rather than workers, take coworkers - oneself; 
. * "coworkers" otherwise captures all workers
. gen cw_not_i = coworkers-1
{txt} 57{com}. gen sh_im_cw_noi = im_coworker/cw_not_i
{txt} 58{com}. gen sh_im_cw_noi_swe = sh_im_cw_noi if IFAUkod==0
{txt} 59{com}. 
. 
. /////////////////////////////////////////
> //NOW VARIABLES USED AS CONTROLS; 
. // MEAN WAGE, AGE AND SEX AT WORKPLACE 
. ///////////////////////////////////////
> 
. ///share young co-workers
> gen young_cw = 1 if age<30 
{txt} 60{com}. 
. ///per workplace
> bysort ArbstId: egen young_cw_wp = total(young_cw)
{txt} 61{com}. gen share_young_cw_wp= young_cw_wp/coworkers
{txt} 62{com}. 
. ///share male coworkers? 
> gen male_cw = 1 if Kon==1
{txt} 63{com}. 
. bysort ArbstId: egen male_cw_wp = total(male_cw)
{txt} 64{com}. gen share_male_cw_wp= male_cw_wp/coworkers
{txt} 65{com}. 
. ///wage at workplace
> bysort ArbstId: egen wage_cw_wp = mean(LoneInk)
{txt} 66{com}. 
. 
. 
. ///////////////////////////////
> //NOW SEPARATE TREATMENT BASED
. //ON SKILL LEVEL
. /////////////////////////
> 
. ///high and low skilled use first digit in SSYK
> capture gen SSKY_str = substr(SSYK3, 1,1)
{txt} 67{com}. capture gen SSKY_str = substr(ssyk3_2012, 1,1)
{txt} 68{com}. encode SSKY_str, gen(SSKY1)
{txt} 69{com}. gen high_skilled=1 if SSKY1==1 | SSKY1==2 | SSKY1==3
{txt} 70{com}. gen low_skilled =1 if SSKY1>3 & SSKY1!=. 
{txt} 71{com}. 
. ///high and low skilled immigrants
> gen highsk_other = 1 if high_skilled==1 & other==1
{txt} 72{com}. gen lowsk_other = 1 if low_skilled==1 & other==1
{txt} 73{com}. 
. ///per workplace
> bysort ArbstId: egen highsk_coworker = total(high_skilled)
{txt} 74{com}. bysort ArbstId: egen lowsk_coworker = total(low_skilled)
{txt} 75{com}. bysort ArbstId: egen highskother_coworker = total(highsk_other)
{txt} 76{com}. bysort ArbstId: egen lowskother_coworker = total(lowsk_other)
{txt} 77{com}. 
. ///now condition the created workplace variables on being swedish
> foreach x in highsk lowsk highskother lowskother  {c -(}
{txt} 78{com}. gen share_`x'_cworker = `x'_coworker/coworkers
{txt} 79{com}. gen share_`x'_cworker_swe = share_`x'_cworker if IFAUkod==0
{txt} 80{com}. gen `x'_coworker_swe = `x'_coworker if IFAUkod==0
{txt} 81{com}. {c )-}
{txt} 82{com}. 
. ///generate a matched skill level - that is, calculate the 
> *number of imm coworkers within the same skill cell
. gen highskillmatch = highskother_coworker if IFAUkod==0 & high_skilled==1
{txt} 83{com}. gen lowskillmatch = lowskother_coworker if IFAUkod==0 & low_skilled==1
{txt} 84{com}. 
. gen share_matchedhigh_cworker = highskillmatch/highsk_coworker
{txt} 85{com}. gen share_matchedlow_cworker = lowskillmatch/lowsk_coworker
{txt} 86{com}. 
. gen matchedcoworkers = share_matchedhigh_cworker
{txt} 87{com}. replace matchedcoworkers = share_matchedlow_cworker if matchedcoworkers==.
{txt} 88{com}. 
. gen crossskill_highnative = lowskother_coworker if IFAUkod==0 & high_skilled==1
{txt} 89{com}. gen crossskill_lownative = highskother_coworker if IFAUkod==0 & low_skilled==1
{txt} 90{com}. 
. gen sharecrossskill_highnative = crossskill_highnative/lowsk_coworker
{txt} 91{com}. gen sharecrossskill_lownative = crossskill_lownative/highsk_coworker 
{txt} 92{com}.   
. gen crossskill = sharecrossskill_highnative
{txt} 93{com}. replace crossskill = sharecrossskill_lownative if crossskill==.
{txt} 94{com}. 
. *Alternative 
. gen hsnew = highsk_coworker-1 if high_skilled==1
{txt} 95{com}. gen lsnew = lowsk_coworker-1 if low_skilled==1
{txt} 96{com}. 
. gen share_match_high_cworker = highskillmatch/hsnew
{txt} 97{com}. gen share_match_low_cworker = lowskillmatch/lsnew
{txt} 98{com}. 
. gen matchedcw = share_match_high_cworker if high_skilled==1
{txt} 99{com}. replace matchedcw = share_match_low_cworker if low_skilled==1
{txt}100{com}. 
. *Do one where we divide the number of matched with total coworkers
. gen share_matchedhigh_allcworker = highskillmatch/coworkers
{txt}101{com}. gen share_matchedlow_allcworker = lowskillmatch/coworkers
{txt}102{com}. 
. gen matchedcoworkers_all = share_matchedhigh_allcworker
{txt}103{com}. replace matchedcoworkers_all = share_matchedlow_allcworker if matchedcoworkers_all==.
{txt}104{com}. 
.  
.  ///per workplace - create 1 digit SSYK variable
> tab SSKY1, gen(SSYK1)
{txt}105{com}. 
. foreach b of numlist 1(1)11 {c -(}
{txt}106{com}. gen SSYK1`b'other = SSYK1`b' if other==1
{txt}107{com}. {c )-}
{txt}108{com}. 
. foreach b of numlist 1(1)11 {c -(}
{txt}109{com}. bysort ArbstId: egen SSYK1`b'_coworker = total(SSYK1`b')
{txt}110{com}. bysort ArbstId: egen SSYK1`b'_othercw = total(SSYK1`b'other)
{txt}111{com}. {c )-}
{txt}112{com}. 
. ///drop oneself, so we divide with CO-workers
> foreach b of numlist 1(1)11 {c -(}
{txt}113{com}. replace SSYK1`b'_coworker = SSYK1`b'_coworker-1 if SSYK1`b' ==1 
{txt}114{com}. {c )-}
{txt}115{com}. 
. ///now take share and condition the created workplace variables on being swedish
> foreach b of numlist 1(1)11 {c -(}
{txt}116{com}. gen share_ssyk1`b'_cworker = SSYK1`b'_othercw/SSYK1`b'_coworker
{txt}117{com}. gen share_ssyk1`b'_cworker_swe = share_ssyk1`b'_cworker if IFAUkod==0
{txt}118{com}. {c )-}
{txt}119{com}. 
. ///one variable
> gen share_ssyk1=.
{txt}120{com}. 
. foreach b of numlist 1(1)11 {c -(}
{txt}121{com}. replace share_ssyk1 = share_ssyk1`b'_cworker_swe if SSYK1`b' ==1 
{txt}122{com}. {c )-}
{txt}123{com}. 
. ///not in the same occupation code
> gen non_ssyk1 =.
{txt}124{com}. foreach b of numlist 1(1)11 {c -(}
{txt}125{com}. replace non_ssyk1 = im_coworker-SSYK1`b'_othercw if SSYK1`b' ==1 & IFAUkod==0
{txt}126{com}. {c )-}
{txt}127{com}. 
. ///standardize with all coworkers not in the same occupation
> foreach b of numlist 1(1)11 {c -(}
{txt}128{com}. replace SSYK1`b'_coworker = SSYK1`b'_coworker+1 if SSYK1`b' ==1 
{txt}129{com}. {c )-}
{txt}130{com}. 
. gen non_ssyk1_all =.
{txt}131{com}. foreach b of numlist 1(1)11 {c -(}
{txt}132{com}. replace non_ssyk1_all = coworkers-SSYK1`b'_coworker if SSYK1`b' ==1 & IFAUkod==0
{txt}133{com}. {c )-}
{txt}134{com}. gen share_non_ssyk1 = non_ssyk1/non_ssyk1_all
{txt}135{com}. 
. 
. ///missing info on some   
> replace share_ssyk1=. if SSYK11==1 
{txt}136{com}. replace share_non_ssyk1=. if SSYK11==1 
{txt}137{com}. 
. 
. 
. 
. 
. /////////////////////////////////////////
> //NOW CREATE DIFFERING TREATMENTS 
. ///DEPENDING ON SIZE OF WORKPLACE
> ///////////////////////////////////////
> 
. cumul coworkers_swe, gen(cumulworkers)
{txt}138{com}. gen share_im_cworker_swe_smwp = sh_im_cw_noi_swe if cumulworkers<0.5 & cumulworkers!=.
{txt}139{com}. gen share_im_cworker_swe_bigwp = sh_im_cw_noi_swe if cumulworkers>0.5 & cumulworkers!=.
{txt}140{com}. 
. 
. gen share_matched_big=  matchedcw if cumulworkers>0.5 & cumulworkers!=.
{txt}141{com}. gen share_matched_small=  matchedcw if cumulworkers<0.5 & cumulworkers!=.
{txt}142{com}. gen share_cross_big= crossskill if cumulworkers>0.5 & cumulworkers!=.
{txt}143{com}. gen share_cross_small= crossskill if cumulworkers<0.5 & cumulworkers!=.
{txt}144{com}. 
. 
. *DIVIDE THE WORKPLACE INTO BIG AND SMALL WORKPLACES BASED ON SHARE OF 
. *SAME SKILL WORKERS
. cumul matchedcw, gen(cumulmatchedcw)
{txt}145{com}. gen share_matched_swe_smwp = matchedcw if cumulmatchedcw<0.5 & cumulmatchedcw!=.
{txt}146{com}. gen share_matched_swe_bigwp = matchedcw if cumulmatchedcw>0.5 & cumulmatchedcw!=.
{txt}147{com}. gen share_cross_bigwp= crossskill if cumulmatchedcw>0.5 & cumulmatchedcw!=.
{txt}148{com}. gen share_cross_smallwp= crossskill if cumulmatchedcw<0.5 & cumulmatchedcw!=.
{txt}149{com}. 
. 
. /////////////////////////////////////////
> //FOR DESCRIPTIVE PURPOSES
. ///////////////////////////////////////
> 
. ///how long have someone stayed in Sweden
> gen yearincountry = `y'-im_year if IFAUkod!=0 & im_year!=0
{txt}150{com}. replace yearincountry=. if yearincountry<0
{txt}151{com}. 
. ///four categories of new, medium, established, old
> gen new_im = 1 if yearincountry<6 & other==1
{txt}152{com}. gen mediumnew_im =1 if yearincountry>5 & yearincountry<11 & other==1
{txt}153{com}. gen notnew_im =1 if yearincountry>10 & yearincountry<16 & other==1
{txt}154{com}. gen old_im = 1 if yearincountry>15 & other==1
{txt}155{com}. 
. ///per workplace
> bysort ArbstId: egen newim_coworker = total(new_im)
{txt}156{com}. bysort ArbstId: egen mediumnewim_coworker = total(mediumnew_im)
{txt}157{com}. bysort ArbstId: egen notnewim_coworker = total(notnew_im)
{txt}158{com}. bysort ArbstId: egen oldim_coworker = total(old_im)
{txt}159{com}. 
. ///now condition the created workplace variables on being swedish
> foreach x in newim mediumnewim notnewim oldim  {c -(}
{txt}160{com}. gen share_`x'_cworker = `x'_coworker/coworkers
{txt}161{com}. gen share_`x'_cworker_swe = share_`x'_cworker if IFAUkod==0
{txt}162{com}. gen `x'_coworker_swe = `x'_coworker if IFAUkod==0
{txt}163{com}. {c )-}
{txt}164{com}. 
. 
. ////////////////
> ///ROBUSTNESS
> //////////////////
> 
. //FIXED EFFECTS FOR INDUSTRY SECTOR
. 
. /// National sector-number - want a number for im_workers in each sector nationally
> 
. /// Use 2002 for 2006, since 2007 version not available for 2006, 
> /// use 2-digits (about 60 sectors)
> tostring AstSNI, gen(AstSNI_str)
{txt}165{com}. gen sector_2dgt = substr(AstSNI_str, 1, 2)
{txt}166{com}. 
. ///#employees in sector, #imm employees in sector
> bysort sector_2dgt: gen sector_empl = _N
{txt}167{com}. bysort sector_2dgt: egen sector_empl_im = total(other)
{txt}168{com}. gen sector_share_im =  sector_empl_im/sector_empl
{txt}169{com}. 
. ///Create fixed effects for sector
> gen deviation_sector = sh_im_cw_noi_swe-sector_share_im 
{txt}170{com}. 
. 
. 
. 
. ///////////////////////////////
> //USE THE OFFSHORING DATA TO GET
. //INFO ON ROUTINE TASK JOBS
. ////////////////////////////
> 
. 
. ///use first 2 digit in SSYK
> capture gen SSYK_str2 = substr(SSYK3, 1,2)
{txt}171{com}. capture gen SSYK_str2 = substr(SSYK4_96, 1,2)
{txt}172{com}. 
. rename SSYK_str2 SSYK2
{txt}173{com}. 
. merge m:1 SSYK2 using "E:\ProjData\IntegrationSD\raw\RTI_and_offshoring.dta" 
{txt}174{com}. drop _merge
{txt}175{com}. 
. rename SSYK2 SSYK_str2
{txt}176{com}. 
. encode SSYK_str2, gen(SSYK2)
{txt}177{com}. 
. ///per workplace - create 2 digit SSYK variable
> tab SSYK2, gen(SSYK2)
{txt}178{com}. 
. foreach b of numlist 1(1)28 {c -(}
{txt}179{com}. gen SSYK2`b'other = SSYK2`b' if other==1
{txt}180{com}. {c )-}
{txt}181{com}. 
. foreach b of numlist 1(1)28 {c -(}
{txt}182{com}. bysort ArbstId: egen SSYK2`b'_coworker = total(SSYK2`b')
{txt}183{com}. bysort ArbstId: egen SSYK2`b'_othercw = total(SSYK2`b'other)
{txt}184{com}. {c )-}
{txt}185{com}. 
. ///drop oneself, so we divide with CO-workers
> foreach b of numlist 1(1)28 {c -(}
{txt}186{com}. replace SSYK2`b'_coworker = SSYK2`b'_coworker-1 if SSYK2`b' ==1 
{txt}187{com}. {c )-}
{txt}188{com}. 
. ///now take share and condition the created workplace variables on being swedish
> foreach b of numlist 1(1)28 {c -(}
{txt}189{com}. gen share_ssyk2`b'_cworker = SSYK2`b'_othercw/SSYK2`b'_coworker
{txt}190{com}. gen share_ssyk2`b'_cworker_swe = share_ssyk2`b'_cworker if IFAUkod==0
{txt}191{com}. {c )-}
{txt}192{com}. 
. ///one variable
> gen share_ssyk2=.
{txt}193{com}. 
. foreach b of numlist 1(1)28 {c -(}
{txt}194{com}. replace share_ssyk2 = share_ssyk2`b'_cworker_swe if SSYK2`b' ==1 
{txt}195{com}. {c )-}
{txt}196{com}. 
. ///not in the same occupation code
> gen non_ssyk2 =.
{txt}197{com}. foreach b of numlist 1(1)28 {c -(}
{txt}198{com}. replace non_ssyk2 = im_coworker-SSYK2`b'_othercw if SSYK2`b' ==1 & IFAUkod==0
{txt}199{com}. {c )-}
{txt}200{com}. 
. ///standardize with all coworkers not in the same occupation
> foreach b of numlist 1(1)28 {c -(}
{txt}201{com}. replace SSYK2`b'_coworker = SSYK2`b'_coworker+1 if SSYK2`b' ==1 
{txt}202{com}. {c )-}
{txt}203{com}. 
. gen non_ssyk2_all =.
{txt}204{com}. foreach b of numlist 1(1)28 {c -(}
{txt}205{com}. replace non_ssyk2_all = coworkers-SSYK2`b'_coworker if SSYK2`b' ==1 & IFAUkod==0
{txt}206{com}. {c )-}
{txt}207{com}. gen share_non_ssyk2 = non_ssyk2/non_ssyk2_all
{txt}208{com}. 
. 
. ///missing info on some + militaries (no RTI) and politicians -  
> replace share_ssyk2=. if SSYK21==1 | SSYK22==1 | SSYK23==1
{txt}209{com}. replace share_ssyk2=. if occupation==.
{txt}210{com}. replace share_non_ssyk2=. if SSYK21==1 | SSYK22==1 | SSYK23==1
{txt}211{com}. replace share_non_ssyk2=. if occupation==.
{txt}212{com}. 
. ///RTI codes: 
> gen share_topRTI = sh_im_cw_noi_swe if RTI_group==1 | RTI_group==2
{txt}213{com}. gen share_midtopRTI = sh_im_cw_noi_swe if RTI_group==3 | RTI_group==4
{txt}214{com}. gen share_midbottomRTI = sh_im_cw_noi_swe if RTI_group==5 | RTI_group==6
{txt}215{com}. gen share_bottomRTI = sh_im_cw_noi_swe if RTI_group==7 | RTI_group==8
{txt}216{com}. 
. gen share_ssyk2_topRTI = share_ssyk2 if RTI_group==1 | RTI_group==2
{txt}217{com}. gen share_ssyk2_midtopRTI = share_ssyk2 if RTI_group==3 | RTI_group==4
{txt}218{com}. gen share_ssyk2_midbottomRTI = share_ssyk2 if RTI_group==5 | RTI_group==6
{txt}219{com}. gen share_ssyk2_bottomRTI = share_ssyk2 if RTI_group==7 | RTI_group==8
{txt}220{com}. 
. gen share_matched_topRTI = matchedcw if RTI_group==1 | RTI_group==2
{txt}221{com}. gen share_cross_topRTI = crossskill if RTI_group==1 | RTI_group==2
{txt}222{com}. gen share_matched_bottomRTI = matchedcw if RTI_group==7 | RTI_group==8
{txt}223{com}. gen share_cross_bottomRTI = crossskill if RTI_group==7 | RTI_group==8
{txt}224{com}. 
. 
. 
. 
. //big and small workplaces INTERACTED WITH SKILL LEVEL
. gen share_ssyk2_big= share_ssyk2 if cumulworkers>0.5 & cumulworkers!=.
{txt}225{com}. gen share_ssyk2_small= share_ssyk2 if cumulworkers<0.5 & cumulworkers!=.
{txt}226{com}. gen share_non_ssyk2_big= share_non_ssyk2 if cumulworkers>0.5 & cumulworkers!=.
{txt}227{com}. gen share_non_ssyk2_small= share_non_ssyk2 if cumulworkers<0.5 & cumulworkers!=.
{txt}228{com}. 
. 
. 
. 
. *oTHER
. 
. ///total workers
> gen workers = 1 
{txt}229{com}. gen workers_swe = 1 if IFAUkod==0
{txt}230{com}. 
. 
. 
. ///keep
> keep LopNr im_coworker coworkers share_im_cworker workers workers_swe ///
> share_im_cworker_swe im_coworker_swe coworkers_swe ArbstId ///
> Sektorkod deviation_sector sector_share_im share_matched_swe_smwp share_matched_swe_bigwp ///
> latin_coworker mena_coworker asia_coworker africa_coworker rest_coworker nordic_coworker western_coworker ///
> share_latin_cworker share_latin_cworker_swe latin_coworker_swe share_mena_cworker /// 
> share_mena_cworker_swe mena_coworker_swe share_asia_cworker share_asia_cworker_swe ///
> asia_coworker_swe share_africa_cworker share_africa_cworker_swe africa_coworker_swe ///
> share_rest_cworker share_rest_cworker_swe rest_coworker_swe share_nordic_cworker ///
> share_nordic_cworker_swe nordic_coworker_swe share_western_cworker ///
> share_western_cworker_swe western_coworker_swe new_im mediumnew_im notnew_im old_im ///
> yearincountry newim_coworker mediumnewim_coworker notnewim_coworker oldim_coworker /// 
> share_newim_cworker share_newim_cworker_swe newim_coworker_swe ///
> share_mediumnewim_cworker share_mediumnewim_cworker_swe mediumnewim_coworker_swe ///
> share_notnewim_cworker share_notnewim_cworker_swe notnewim_coworker_swe ///
> share_oldim_cworker share_oldim_cworker_swe oldim_coworker_swe ///
> high_skilled low_skilled highsk_coworker lowsk_coworker highsk_other lowsk_other ///
> highskother_coworker lowskother_coworker share_highsk_cworker share_highsk_cworker_swe ///
> highsk_coworker_swe share_lowsk_cworker share_lowsk_cworker_swe lowsk_coworker_swe ///
> share_highskother_cworker share_highskother_cworker_swe highskother_coworker_swe ///
> share_lowskother_cworker share_lowskother_cworker_swe lowskother_coworker_swe ///
> matchedcoworkers share_matchedhigh_cworker share_matchedlow_cworker ///
> sharecrossskill_highnative sharecrossskill_lownative crossskill matchedcoworkers_all share_matchedhigh_allcworker ///
> share_matchedlow_allcworker share_im_cworker_swe_smwp share_im_cworker_swe_bigwp ///
> share_young_cw_wp share_male_cw_wp ///
> share_ssyk2 wage_cw_wp share_ssyk2_topRTI share_ssyk2_bottomRTI ///
>  share_ssyk2_midbottomRTI share_ssyk2_midtopRTI share_non_ssyk2 share_ssyk2_big ///
>  share_ssyk2_small share_non_ssyk2_big share_non_ssyk2_small stdRTI matchedcw sh_im_cw_noi_swe ///
>  share_topRTI share_midtopRTI share_midbottomRTI share_bottomRTI share_ssyk1 share_non_ssyk1 ///
>  share_matched_big share_matched_small share_cross_big share_cross_small share_matched_topRTI ///
>  share_cross_topRTI share_matched_bottomRTI share_cross_bottomRTI share_cross_bigwp share_cross_smallwp
{txt}231{com}.  
.  
. ///Left with: 
> ///check amount of workplaces
> *bysort ArbstId: gen diff_jobs = _n
. *count if diff_jobs==1
. *2006: 3,604,076 workers connected to a workplace id 192,088 workplaces
. *2010: 3,684,633 workers connected to a workplace id 203,576 workplaces
. *2014: 3,852,892 workers connected to a workplace id 211,953 workplaces
. 
. save "E:\ProjData\IntegrationSD\temp\workplace_`y'.dta", replace
{txt}232{com}. 
. {c )-}
{txt}(2,788,465 observations deleted)
(969,166 observations deleted)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

        {txt}tag {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          0 {c |}{res}  3,675,381      100.00      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,675,381      100.00
{txt}(0 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}      12,396,830
{txt}{col 9}from master{col 30}{res}             118{txt}  (_merge==1)
{col 9}from using{col 30}{res}      12,396,712{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,675,263{txt}  (_merge==3)
{col 5}{hline 41}
(12,396,830 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       7,322,068
{txt}{col 9}from master{col 30}{res}       3,123,956{txt}  (_merge==1)
{col 9}from using{col 30}{res}       4,198,112{txt}  (_merge==2)

{col 5}matched{col 30}{res}         803,030{txt}  (_merge==3)
{col 5}{hline 41}
(4,198,112 observations deleted)
Datum was {res:long} now {res:str8}
im_year: all characters numeric; {res}replaced {txt}as {res}int
{txt}(3123956 missing values generated)
{res}{txt}(3,123,970 missing values generated)
im_month: all characters numeric; {res}replaced {txt}as {res}byte
{txt}(3123970 missing values generated)
{res}
{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(150,858 observations deleted)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(100,865 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}      12,397,357
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}      12,397,357{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,675,263{txt}  (_merge==3)
{col 5}{hline 41}
(12,397,357 observations deleted)
FodArMan was {res:long} now {res:str6}
birth_year: all characters numeric; {res}replaced {txt}as {res}int
{txt}(417,923 missing values generated)
(3,570,805 missing values generated)
(3,630,757 missing values generated)
(3,566,667 missing values generated)
(3,514,951 missing values generated)
(3,644,663 missing values generated)
(3,606,826 missing values generated)
(3,634,978 missing values generated)
(3,655,870 missing values generated)
(3,673,666 missing values generated)
(71,187 observations deleted)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(2,894,422 missing values generated)
(1,789,969 missing values generated)
(3,283,287 missing values generated)
(320,789 missing values generated)
(3,589,367 missing values generated)
(3,462,843 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(3,319,619 missing values generated)
(692,812 missing values generated)
(3,319,619 missing values generated)
(692,812 missing values generated)
(3,319,619 missing values generated)
(2,911,264 real changes made)
(3,319,619 missing values generated)
(692,812 missing values generated)
(3,322,703 missing values generated)
(1,267,355 missing values generated)
(3,322,703 missing values generated)
(2,336,721 real changes made)
(3,283,287 missing values generated)
(320,789 missing values generated)
(3,364,355 missing values generated)
(700,745 missing values generated)
(3,364,355 missing values generated)
(2,903,331 real changes made)
(3,319,619 missing values generated)
(692,812 missing values generated)
(3,319,619 missing values generated)
(2,911,264 real changes made)

      SSKY1 {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          * {c |}{res}    131,075        3.64        3.64
{txt}          0 {c |}{res}     10,800        0.30        3.94
{txt}          1 {c |}{res}    178,914        4.96        8.90
{txt}          2 {c |}{res}    666,393       18.49       27.39
{txt}          3 {c |}{res}    675,696       18.75       46.14
{txt}          4 {c |}{res}    341,639        9.48       55.62
{txt}          5 {c |}{res}    684,145       18.98       74.60
{txt}          6 {c |}{res}     23,173        0.64       75.24
{txt}          7 {c |}{res}    299,885        8.32       83.56
{txt}          8 {c |}{res}    385,241       10.69       94.25
{txt}          9 {c |}{res}    207,115        5.75      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,604,076      100.00
{txt}(3,448,134 missing values generated)
(3,448,134 missing values generated)
(3,448,134 missing values generated)
(3,448,134 missing values generated)
(3,448,134 missing values generated)
(3,448,134 missing values generated)
(3,448,134 missing values generated)
(3,448,134 missing values generated)
(3,448,134 missing values generated)
(3,448,134 missing values generated)
(3,448,134 missing values generated)
(131,075 real changes made)
(10,800 real changes made)
(178,914 real changes made)
(666,393 real changes made)
(675,696 real changes made)
(341,639 real changes made)
(684,145 real changes made)
(23,173 real changes made)
(299,885 real changes made)
(385,241 real changes made)
(207,115 real changes made)
(1,688,243 missing values generated)
(1,937,693 missing values generated)
(3,519,431 missing values generated)
(3,526,259 missing values generated)
(1,044,574 missing values generated)
(1,342,400 missing values generated)
(1,290,989 missing values generated)
(1,548,824 missing values generated)
(818,283 missing values generated)
(1,127,265 missing values generated)
(1,041,259 missing values generated)
(1,331,887 missing values generated)
(1,267,520 missing values generated)
(1,548,946 missing values generated)
(3,272,592 missing values generated)
(3,311,278 missing values generated)
(1,829,640 missing values generated)
(2,030,341 missing values generated)
(2,240,504 missing values generated)
(2,406,853 missing values generated)
(1,594,144 missing values generated)
(1,849,593 missing values generated)
(3,604,076 missing values generated)
(78,391 real changes made)
(10,031 real changes made)
(131,608 real changes made)
(583,359 real changes made)
(597,333 real changes made)
(276,662 real changes made)
(573,043 real changes made)
(17,597 real changes made)
(255,869 real changes made)
(315,096 real changes made)
(140,315 real changes made)
(3,604,076 missing values generated)
(105,879 real changes made)
(10,606 real changes made)
(167,972 real changes made)
(601,879 real changes made)
(623,638 real changes made)
(309,980 real changes made)
(594,221 real changes made)
(21,469 real changes made)
(272,848 real changes made)
(327,719 real changes made)
(159,510 real changes made)
(131,075 real changes made)
(10,800 real changes made)
(178,914 real changes made)
(666,393 real changes made)
(675,696 real changes made)
(341,639 real changes made)
(684,145 real changes made)
(23,173 real changes made)
(299,885 real changes made)
(385,241 real changes made)
(207,115 real changes made)
(3,604,076 missing values generated)
(105,879 real changes made)
(10,606 real changes made)
(167,972 real changes made)
(601,879 real changes made)
(623,638 real changes made)
(309,980 real changes made)
(594,221 real changes made)
(21,469 real changes made)
(272,848 real changes made)
(327,719 real changes made)
(159,510 real changes made)
(546,139 missing values generated)
(78,391 real changes made, 78,391 to missing)
(104,473 real changes made, 104,473 to missing)
(2,006,216 missing values generated)
(2,006,215 missing values generated)
(2,007,081 missing values generated)
(2,058,019 missing values generated)
(2,046,141 missing values generated)
(2,543,917 missing values generated)
(2,032,551 missing values generated)
(2,032,550 missing values generated)
(2,164,261 missing values generated)
(2,478,467 missing values generated)
(3,200,307 missing values generated)
(49 real changes made, 49 to missing)
(3,585,071 missing values generated)
(3,584,960 missing values generated)
(3,574,811 missing values generated)
(3,515,520 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
(408,355 missing values generated)
AstSNI_str generated as {res:str5}
(408,355 missing values generated)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         141,876
{txt}{col 9}from master{col 30}{res}         141,875{txt}  (_merge==1)
{col 9}from using{col 30}{res}               1{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,462,201{txt}  (_merge==3)
{col 5}{hline 41}
{res}
      {txt}SSYK2 {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
         ** {c |}{res}    131,075        3.64        3.64
{txt}         01 {c |}{res}     10,800        0.30        3.94
{txt}         11 {c |}{res}      2,009        0.06        3.99
{txt}         12 {c |}{res}    135,105        3.75        7.74
{txt}         13 {c |}{res}     41,800        1.16        8.90
{txt}         21 {c |}{res}    147,685        4.10       13.00
{txt}         22 {c |}{res}     82,642        2.29       15.29
{txt}         23 {c |}{res}    199,804        5.54       20.84
{txt}         24 {c |}{res}    236,262        6.56       27.39
{txt}         31 {c |}{res}    174,871        4.85       32.24
{txt}         32 {c |}{res}    107,940        2.99       35.24
{txt}         33 {c |}{res}     81,689        2.27       37.50
{txt}         34 {c |}{res}    311,196        8.63       46.14
{txt}         41 {c |}{res}    274,400        7.61       53.75
{txt}         42 {c |}{res}     67,239        1.87       55.62
{txt}         51 {c |}{res}    508,994       14.12       69.74
{txt}         52 {c |}{res}    175,151        4.86       74.60
{txt}         61 {c |}{res}     23,173        0.64       75.24
{txt}         62 {c |}{res}          1        0.00       75.24
{txt}         71 {c |}{res}    158,147        4.39       79.63
{txt}         72 {c |}{res}    117,967        3.27       82.90
{txt}         73 {c |}{res}     11,008        0.31       83.21
{txt}         74 {c |}{res}     12,763        0.35       83.56
{txt}         81 {c |}{res}     50,637        1.40       84.97
{txt}         82 {c |}{res}    216,659        6.01       90.98
{txt}         83 {c |}{res}    117,945        3.27       94.25
{txt}         91 {c |}{res}    157,400        4.37       98.62
{txt}         92 {c |}{res}      2,081        0.06       98.68
{txt}         93 {c |}{res}     47,634        1.32      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,604,077      100.00
{txt}(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(3,448,135 missing values generated)
(131,075 real changes made)
(10,800 real changes made)
(2,009 real changes made)
(135,105 real changes made)
(41,800 real changes made)
(147,685 real changes made)
(82,642 real changes made)
(199,804 real changes made)
(236,262 real changes made)
(174,871 real changes made)
(107,940 real changes made)
(81,689 real changes made)
(311,196 real changes made)
(274,400 real changes made)
(67,239 real changes made)
(508,994 real changes made)
(175,151 real changes made)
(23,173 real changes made)
(1 real change made)
(158,147 real changes made)
(117,967 real changes made)
(11,008 real changes made)
(12,763 real changes made)
(50,637 real changes made)
(216,659 real changes made)
(117,945 real changes made)
(157,400 real changes made)
(2,081 real changes made)
(1,688,244 missing values generated)
(1,937,694 missing values generated)
(3,519,432 missing values generated)
(3,526,260 missing values generated)
(3,474,115 missing values generated)
(3,486,346 missing values generated)
(1,355,050 missing values generated)
(1,609,960 missing values generated)
(2,822,542 missing values generated)
(2,924,443 missing values generated)
(2,332,124 missing values generated)
(2,470,797 missing values generated)
(2,877,599 missing values generated)
(2,961,281 missing values generated)
(2,594,957 missing values generated)
(2,708,035 missing values generated)
(1,704,526 missing values generated)
(1,918,018 missing values generated)
(2,004,108 missing values generated)
(2,177,814 missing values generated)
(2,779,710 missing values generated)
(2,881,340 missing values generated)
(2,924,684 missing values generated)
(3,000,010 missing values generated)
(1,433,647 missing values generated)
(1,674,818 missing values generated)
(1,157,460 missing values generated)
(1,434,574 missing values generated)
(2,445,473 missing values generated)
(2,578,114 missing values generated)
(1,666,797 missing values generated)
(1,910,097 missing values generated)
(2,471,044 missing values generated)
(2,603,263 missing values generated)
(3,272,593 missing values generated)
(3,311,279 missing values generated)
(3,604,077 missing values generated)
(3,604,077 missing values generated)
(2,448,688 missing values generated)
(2,572,879 missing values generated)
(2,614,082 missing values generated)
(2,729,217 missing values generated)
(3,289,036 missing values generated)
(3,327,091 missing values generated)
(3,401,612 missing values generated)
(3,429,526 missing values generated)
(3,249,701 missing values generated)
(3,290,240 missing values generated)
(2,633,090 missing values generated)
(2,759,023 missing values generated)
(2,800,628 missing values generated)
(2,897,664 missing values generated)
(1,777,439 missing values generated)
(2,012,336 missing values generated)
(3,551,388 missing values generated)
(3,558,837 missing values generated)
(3,604,077 missing values generated)
(78,391 real changes made)
(10,031 real changes made)
(919 real changes made)
(106,967 real changes made)
(17,843 real changes made)
(127,274 real changes made)
(65,910 real changes made)
(174,014 real changes made)
(203,520 real changes made)
(150,411 real changes made)
(93,622 real changes made)
(71,530 real changes made)
(266,577 real changes made)
(218,263 real changes made)
(50,852 real changes made)
(417,645 real changes made)
(146,571 real changes made)
(17,597 real changes made)
(0 real changes made)
(134,416 real changes made)
(98,429 real changes made)
(8,407 real changes made)
(8,517 real changes made)
(43,326 real changes made)
(169,920 real changes made)
(96,911 real changes made)
(101,034 real changes made)
(1,043 real changes made)
(3,604,077 missing values generated)
(105,879 real changes made)
(10,606 real changes made)
(1,903 real changes made)
(127,461 real changes made)
(38,608 real changes made)
(133,907 real changes made)
(69,676 real changes made)
(179,751 real changes made)
(218,545 real changes made)
(161,211 real changes made)
(97,473 real changes made)
(75,413 real changes made)
(289,541 real changes made)
(249,483 real changes made)
(60,497 real changes made)
(433,576 real changes made)
(160,645 real changes made)
(21,469 real changes made)
(0 real changes made)
(146,511 real changes made)
(106,165 real changes made)
(9,992 real changes made)
(10,180 real changes made)
(45,453 real changes made)
(178,144 real changes made)
(104,122 real changes made)
(117,923 real changes made)
(1,741 real changes made)
(131,075 real changes made)
(10,800 real changes made)
(2,009 real changes made)
(135,105 real changes made)
(41,800 real changes made)
(147,685 real changes made)
(82,642 real changes made)
(199,804 real changes made)
(236,262 real changes made)
(174,871 real changes made)
(107,940 real changes made)
(81,689 real changes made)
(311,196 real changes made)
(274,400 real changes made)
(67,239 real changes made)
(508,994 real changes made)
(175,151 real changes made)
(23,173 real changes made)
(1 real change made)
(158,147 real changes made)
(117,967 real changes made)
(11,008 real changes made)
(12,763 real changes made)
(50,637 real changes made)
(216,659 real changes made)
(117,945 real changes made)
(157,400 real changes made)
(2,081 real changes made)
(3,604,077 missing values generated)
(105,879 real changes made)
(10,606 real changes made)
(1,903 real changes made)
(127,461 real changes made)
(38,608 real changes made)
(133,907 real changes made)
(69,676 real changes made)
(179,751 real changes made)
(218,545 real changes made)
(161,211 real changes made)
(97,473 real changes made)
(75,413 real changes made)
(289,541 real changes made)
(249,483 real changes made)
(60,497 real changes made)
(433,576 real changes made)
(160,645 real changes made)
(21,469 real changes made)
(0 real changes made)
(146,511 real changes made)
(106,165 real changes made)
(9,992 real changes made)
(10,180 real changes made)
(45,453 real changes made)
(178,144 real changes made)
(104,122 real changes made)
(117,923 real changes made)
(1,741 real changes made)
(573,221 missing values generated)
(89,341 real changes made, 89,341 to missing)
(0 real changes made)
(116,860 real changes made, 116,860 to missing)
(0 real changes made)
(3,284,105 missing values generated)
(3,269,742 missing values generated)
(2,128,534 missing values generated)
(2,654,691 missing values generated)
(3,326,555 missing values generated)
(3,327,211 missing values generated)
(2,231,835 missing values generated)
(2,740,108 missing values generated)
(3,285,281 missing values generated)
(3,336,000 missing values generated)
(2,682,475 missing values generated)
(2,817,703 missing values generated)
(2,096,743 missing values generated)
(2,320,812 missing values generated)
(2,074,074 missing values generated)
(2,220,084 missing values generated)
(408,356 missing values generated)
file E:\ProjData\IntegrationSD\temp\workplace_2006.dta saved
(3,085,995 observations deleted)
(1,005,604 observations deleted)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

        {txt}tag {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          0 {c |}{res}  3,759,008      100.00      100.00
{txt}          1 {c |}{res}          4        0.00      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,759,012      100.00
{txt}(4 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}      12,313,099
{txt}{col 9}from master{col 30}{res}              66{txt}  (_merge==1)
{col 9}from using{col 30}{res}      12,313,033{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,758,942{txt}  (_merge==3)
{col 5}{hline 41}
(12,313,099 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       7,273,235
{txt}{col 9}from master{col 30}{res}       3,141,087{txt}  (_merge==1)
{col 9}from using{col 30}{res}       4,132,148{txt}  (_merge==2)

{col 5}matched{col 30}{res}         868,994{txt}  (_merge==3)
{col 5}{hline 41}
(4,132,148 observations deleted)
Datum was {res:long} now {res:str8}
im_year: all characters numeric; {res}replaced {txt}as {res}int
{txt}(3141087 missing values generated)
{res}{txt}(3,141,104 missing values generated)
im_month: all characters numeric; {res}replaced {txt}as {res}byte
{txt}(3141104 missing values generated)
{res}
{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(154,597 observations deleted)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(96,542 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}      12,313,678
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}      12,313,678{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,758,942{txt}  (_merge==3)
{col 5}{hline 41}
(12,313,678 observations deleted)
FodArMan was {res:long} now {res:str6}
birth_year: all characters numeric; {res}replaced {txt}as {res}int
{txt}(484,929 missing values generated)
(3,666,802 missing values generated)
(3,708,961 missing values generated)
(3,626,630 missing values generated)
(3,548,517 missing values generated)
(3,723,294 missing values generated)
(3,666,082 missing values generated)
(3,705,235 missing values generated)
(3,732,715 missing values generated)
(3,756,959 missing values generated)
(74,309 observations deleted)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(2,942,428 missing values generated)
(1,836,057 missing values generated)
(3,332,261 missing values generated)
(352,372 missing values generated)
(3,665,341 missing values generated)
(3,499,417 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(3,376,724 missing values generated)
(780,900 missing values generated)
(3,376,724 missing values generated)
(780,900 missing values generated)
(3,376,724 missing values generated)
(2,903,733 real changes made)
(3,376,724 missing values generated)
(780,900 missing values generated)
(3,379,905 missing values generated)
(1,350,619 missing values generated)
(3,379,905 missing values generated)
(2,334,014 real changes made)
(3,332,261 missing values generated)
(352,372 missing values generated)
(3,424,257 missing values generated)
(789,236 missing values generated)
(3,424,257 missing values generated)
(2,895,397 real changes made)
(3,376,724 missing values generated)
(780,900 missing values generated)
(3,376,724 missing values generated)
(2,903,733 real changes made)

      SSKY1 {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          * {c |}{res}    138,307        3.75        3.75
{txt}          0 {c |}{res}     10,710        0.29        4.04
{txt}          1 {c |}{res}    203,355        5.52        9.56
{txt}          2 {c |}{res}    693,860       18.83       28.39
{txt}          3 {c |}{res}    718,005       19.49       47.88
{txt}          4 {c |}{res}    317,337        8.61       56.49
{txt}          5 {c |}{res}    701,919       19.05       75.54
{txt}          6 {c |}{res}     25,973        0.70       76.25
{txt}          7 {c |}{res}    305,347        8.29       84.54
{txt}          8 {c |}{res}    359,793        9.76       94.30
{txt}          9 {c |}{res}    210,027        5.70      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,684,633      100.00
{txt}(3,480,125 missing values generated)
(3,480,125 missing values generated)
(3,480,125 missing values generated)
(3,480,125 missing values generated)
(3,480,125 missing values generated)
(3,480,125 missing values generated)
(3,480,125 missing values generated)
(3,480,125 missing values generated)
(3,480,125 missing values generated)
(3,480,125 missing values generated)
(3,480,125 missing values generated)
(138,307 real changes made)
(10,710 real changes made)
(203,355 real changes made)
(693,860 real changes made)
(718,005 real changes made)
(317,337 real changes made)
(701,919 real changes made)
(25,973 real changes made)
(305,347 real changes made)
(359,793 real changes made)
(210,027 real changes made)
(1,848,045 missing values generated)
(2,118,119 missing values generated)
(3,617,135 missing values generated)
(3,623,433 missing values generated)
(1,062,716 missing values generated)
(1,395,883 missing values generated)
(1,369,363 missing values generated)
(1,655,496 missing values generated)
(867,086 missing values generated)
(1,213,857 missing values generated)
(1,188,415 missing values generated)
(1,503,456 missing values generated)
(1,352,673 missing values generated)
(1,669,387 missing values generated)
(3,344,130 missing values generated)
(3,385,324 missing values generated)
(1,955,488 missing values generated)
(2,172,926 missing values generated)
(2,312,080 missing values generated)
(2,492,290 missing values generated)
(1,766,836 missing values generated)
(2,046,316 missing values generated)
(3,684,633 missing values generated)
(79,059 real changes made)
(10,172 real changes made)
(151,173 real changes made)
(598,234 real changes made)
(627,961 real changes made)
(250,952 real changes made)
(574,527 real changes made)
(18,392 real changes made)
(255,649 real changes made)
(289,927 real changes made)
(132,556 real changes made)
(3,684,633 missing values generated)
(107,717 real changes made)
(10,507 real changes made)
(189,685 real changes made)
(617,006 real changes made)
(655,013 real changes made)
(283,647 real changes made)
(596,813 real changes made)
(23,583 real changes made)
(272,867 real changes made)
(303,269 real changes made)
(151,535 real changes made)
(138,307 real changes made)
(10,710 real changes made)
(203,355 real changes made)
(693,860 real changes made)
(718,005 real changes made)
(317,337 real changes made)
(701,919 real changes made)
(25,973 real changes made)
(305,347 real changes made)
(359,793 real changes made)
(210,027 real changes made)
(3,684,633 missing values generated)
(107,717 real changes made)
(10,507 real changes made)
(189,685 real changes made)
(617,006 real changes made)
(655,013 real changes made)
(283,647 real changes made)
(596,813 real changes made)
(23,583 real changes made)
(272,867 real changes made)
(303,269 real changes made)
(151,535 real changes made)
(619,299 missing values generated)
(79,059 real changes made, 79,059 to missing)
(106,090 real changes made, 106,090 to missing)
(2,078,813 missing values generated)
(2,078,812 missing values generated)
(2,079,712 missing values generated)
(2,133,782 missing values generated)
(2,129,834 missing values generated)
(2,600,691 missing values generated)
(2,106,747 missing values generated)
(2,106,746 missing values generated)
(2,255,257 missing values generated)
(2,531,136 missing values generated)
(3,214,775 missing values generated)
(12 real changes made, 12 to missing)
(3,650,048 missing values generated)
(3,658,657 missing values generated)
(3,661,966 missing values generated)
(3,563,353 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
(472,991 missing values generated)
AstSNI_str generated as {res:str5}
(472,991 missing values generated)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         149,018
{txt}{col 9}from master{col 30}{res}         149,017{txt}  (_merge==1)
{col 9}from using{col 30}{res}               1{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,535,616{txt}  (_merge==3)
{col 5}{hline 41}
{res}
      {txt}SSYK2 {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
         ** {c |}{res}    138,307        3.75        3.75
{txt}         01 {c |}{res}     10,710        0.29        4.04
{txt}         11 {c |}{res}      4,362        0.12        4.16
{txt}         12 {c |}{res}    157,291        4.27        8.43
{txt}         13 {c |}{res}     41,702        1.13        9.56
{txt}         21 {c |}{res}    168,728        4.58       14.14
{txt}         22 {c |}{res}     81,201        2.20       16.35
{txt}         23 {c |}{res}    197,306        5.35       21.70
{txt}         24 {c |}{res}    246,625        6.69       28.39
{txt}         31 {c |}{res}    174,222        4.73       33.12
{txt}         32 {c |}{res}    118,423        3.21       36.34
{txt}         33 {c |}{res}     87,457        2.37       38.71
{txt}         34 {c |}{res}    337,903        9.17       47.88
{txt}         41 {c |}{res}    249,089        6.76       54.64
{txt}         42 {c |}{res}     68,248        1.85       56.49
{txt}         51 {c |}{res}    510,422       13.85       70.35
{txt}         52 {c |}{res}    191,497        5.20       75.54
{txt}         61 {c |}{res}     25,973        0.70       76.25
{txt}         62 {c |}{res}          1        0.00       76.25
{txt}         71 {c |}{res}    174,660        4.74       80.99
{txt}         72 {c |}{res}    109,065        2.96       83.95
{txt}         73 {c |}{res}      9,225        0.25       84.20
{txt}         74 {c |}{res}     12,397        0.34       84.54
{txt}         81 {c |}{res}     51,278        1.39       85.93
{txt}         82 {c |}{res}    183,158        4.97       90.90
{txt}         83 {c |}{res}    125,357        3.40       94.30
{txt}         91 {c |}{res}    163,166        4.43       98.73
{txt}         92 {c |}{res}      2,771        0.08       98.80
{txt}         93 {c |}{res}     44,090        1.20      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,684,634      100.00
{txt}(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(3,480,126 missing values generated)
(138,307 real changes made)
(10,710 real changes made)
(4,362 real changes made)
(157,291 real changes made)
(41,702 real changes made)
(168,728 real changes made)
(81,201 real changes made)
(197,306 real changes made)
(246,625 real changes made)
(174,222 real changes made)
(118,423 real changes made)
(87,457 real changes made)
(337,903 real changes made)
(249,089 real changes made)
(68,248 real changes made)
(510,422 real changes made)
(191,497 real changes made)
(25,973 real changes made)
(1 real change made)
(174,660 real changes made)
(109,065 real changes made)
(9,225 real changes made)
(12,397 real changes made)
(51,278 real changes made)
(183,158 real changes made)
(125,357 real changes made)
(163,166 real changes made)
(2,771 real changes made)
(1,848,046 missing values generated)
(2,118,120 missing values generated)
(3,617,136 missing values generated)
(3,623,434 missing values generated)
(3,377,728 missing values generated)
(3,409,289 missing values generated)
(1,288,926 missing values generated)
(1,592,680 missing values generated)
(2,768,423 missing values generated)
(2,892,752 missing values generated)
(2,400,495 missing values generated)
(2,553,572 missing values generated)
(2,981,588 missing values generated)
(3,073,504 missing values generated)
(2,723,024 missing values generated)
(2,844,448 missing values generated)
(1,811,774 missing values generated)
(2,042,319 missing values generated)
(2,122,201 missing values generated)
(2,305,229 missing values generated)
(2,866,649 missing values generated)
(2,975,548 missing values generated)
(3,044,057 missing values generated)
(3,122,525 missing values generated)
(1,458,794 missing values generated)
(1,733,073 missing values generated)
(1,329,021 missing values generated)
(1,624,502 missing values generated)
(2,552,896 missing values generated)
(2,698,409 missing values generated)
(1,795,429 missing values generated)
(2,066,034 missing values generated)
(2,551,191 missing values generated)
(2,694,531 missing values generated)
(3,344,131 missing values generated)
(3,385,325 missing values generated)
(3,684,634 missing values generated)
(3,684,634 missing values generated)
(2,434,445 missing values generated)
(2,586,749 missing values generated)
(2,816,563 missing values generated)
(2,926,041 missing values generated)
(3,345,180 missing values generated)
(3,388,601 missing values generated)
(3,554,427 missing values generated)
(3,578,348 missing values generated)
(3,153,882 missing values generated)
(3,215,810 missing values generated)
(2,815,867 missing values generated)
(2,935,565 missing values generated)
(2,931,025 missing values generated)
(3,032,808 missing values generated)
(1,976,881 missing values generated)
(2,229,422 missing values generated)
(3,641,824 missing values generated)
(3,647,752 missing values generated)
(3,684,634 missing values generated)
(79,059 real changes made)
(10,172 real changes made)
(2,511 real changes made)
(123,366 real changes made)
(16,644 real changes made)
(143,767 real changes made)
(62,119 real changes made)
(168,542 real changes made)
(211,190 real changes made)
(148,300 real changes made)
(101,510 real changes made)
(76,644 real changes made)
(285,985 real changes made)
(192,799 real changes made)
(50,850 real changes made)
(406,468 real changes made)
(158,666 real changes made)
(18,392 real changes made)
(0 real changes made)
(145,603 real changes made)
(89,665 real changes made)
(6,933 real changes made)
(7,307 real changes made)
(43,921 real changes made)
(141,078 real changes made)
(100,037 real changes made)
(96,637 real changes made)
(1,352 real changes made)
(3,684,634 missing values generated)
(107,717 real changes made)
(10,507 real changes made)
(4,154 real changes made)
(147,265 real changes made)
(38,266 real changes made)
(150,461 real changes made)
(65,934 real changes made)
(174,099 real changes made)
(226,512 real changes made)
(159,104 real changes made)
(105,645 real changes made)
(79,947 real changes made)
(310,317 real changes made)
(222,967 real changes made)
(60,680 real changes made)
(423,227 real changes made)
(173,586 real changes made)
(23,583 real changes made)
(0 real changes made)
(158,407 real changes made)
(97,357 real changes made)
(8,354 real changes made)
(8,749 real changes made)
(46,438 real changes made)
(149,553 real changes made)
(107,278 real changes made)
(112,764 real changes made)
(2,155 real changes made)
(138,307 real changes made)
(10,710 real changes made)
(4,362 real changes made)
(157,291 real changes made)
(41,702 real changes made)
(168,728 real changes made)
(81,201 real changes made)
(197,306 real changes made)
(246,625 real changes made)
(174,222 real changes made)
(118,423 real changes made)
(87,457 real changes made)
(337,903 real changes made)
(249,089 real changes made)
(68,248 real changes made)
(510,422 real changes made)
(191,497 real changes made)
(25,973 real changes made)
(1 real change made)
(174,660 real changes made)
(109,065 real changes made)
(9,225 real changes made)
(12,397 real changes made)
(51,278 real changes made)
(183,158 real changes made)
(125,357 real changes made)
(163,166 real changes made)
(2,771 real changes made)
(3,684,634 missing values generated)
(107,717 real changes made)
(10,507 real changes made)
(4,154 real changes made)
(147,265 real changes made)
(38,266 real changes made)
(150,461 real changes made)
(65,934 real changes made)
(174,099 real changes made)
(226,512 real changes made)
(159,104 real changes made)
(105,645 real changes made)
(79,947 real changes made)
(310,317 real changes made)
(222,967 real changes made)
(60,680 real changes made)
(423,227 real changes made)
(173,586 real changes made)
(23,583 real changes made)
(0 real changes made)
(158,407 real changes made)
(97,357 real changes made)
(8,354 real changes made)
(8,749 real changes made)
(46,438 real changes made)
(149,553 real changes made)
(107,278 real changes made)
(112,764 real changes made)
(2,155 real changes made)
(643,794 missing values generated)
(91,742 real changes made, 91,742 to missing)
(0 real changes made)
(120,739 real changes made, 120,739 to missing)
(0 real changes made)
(3,392,633 missing values generated)
(3,392,359 missing values generated)
(2,169,408 missing values generated)
(2,690,718 missing values generated)
(3,434,052 missing values generated)
(3,446,584 missing values generated)
(2,277,800 missing values generated)
(2,782,325 missing values generated)
(3,393,736 missing values generated)
(3,433,399 missing values generated)
(2,720,619 missing values generated)
(2,854,281 missing values generated)
(2,165,274 missing values generated)
(2,406,220 missing values generated)
(2,142,939 missing values generated)
(2,306,229 missing values generated)
(472,992 missing values generated)
file E:\ProjData\IntegrationSD\temp\workplace_2010.dta saved
(3,086,945 observations deleted)
(1,045,965 observations deleted)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

        {txt}tag {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          0 {c |}{res}  3,932,408      100.00      100.00
{txt}          1 {c |}{res}          4        0.00      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,932,412      100.00
{txt}(4 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}      12,139,771
{txt}{col 9}from master{col 30}{res}             102{txt}  (_merge==1)
{col 9}from using{col 30}{res}      12,139,669{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,932,306{txt}  (_merge==3)
{col 5}{hline 41}
(12,139,771 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       7,213,865
{txt}{col 9}from master{col 30}{res}       3,203,061{txt}  (_merge==1)
{col 9}from using{col 30}{res}       4,010,804{txt}  (_merge==2)

{col 5}matched{col 30}{res}         990,338{txt}  (_merge==3)
{col 5}{hline 41}
(4,010,804 observations deleted)
Datum was {res:long} now {res:str8}
im_year: all characters numeric; {res}replaced {txt}as {res}int
{txt}(3203061 missing values generated)
{res}{txt}(3,203,073 missing values generated)
im_month: all characters numeric; {res}replaced {txt}as {res}byte
{txt}(3203073 missing values generated)
{res}
{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(168,459 observations deleted)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(92,634 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}      12,140,314
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}      12,140,314{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,932,306{txt}  (_merge==3)
{col 5}{hline 41}
(12,140,314 observations deleted)
FodArMan was {res:long} now {res:str6}
birth_year: all characters numeric; {res}replaced {txt}as {res}int
{txt}(593,955 missing values generated)
(3,850,358 missing values generated)
(3,871,149 missing values generated)
(3,764,379 missing values generated)
(3,649,551 missing values generated)
(3,891,328 missing values generated)
(3,807,121 missing values generated)
(3,856,875 missing values generated)
(3,893,530 missing values generated)
(3,929,921 missing values generated)
(79,414 observations deleted)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(3,033,964 missing values generated)
(1,917,228 missing values generated)
(3,414,939 missing values generated)
(1,114,695 missing values generated)
(3,818,692 missing values generated)
(3,663,598 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(3,486,697 missing values generated)
(1,519,358 missing values generated)
(3,486,697 missing values generated)
(1,519,358 missing values generated)
(3,486,697 missing values generated)
(2,333,534 real changes made)
(3,486,697 missing values generated)
(1,519,358 missing values generated)
(3,554,121 missing values generated)
(1,939,976 missing values generated)
(3,554,121 missing values generated)
(1,912,916 real changes made)
(3,414,939 missing values generated)
(1,114,695 missing values generated)
(3,533,207 missing values generated)
(1,531,999 missing values generated)
(3,533,207 missing values generated)
(2,320,893 real changes made)
(3,486,697 missing values generated)
(1,519,358 missing values generated)
(3,486,697 missing values generated)
(2,333,534 real changes made)

      SSKY1 {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          * {c |}{res}    232,323        7.31        7.31
{txt}          0 {c |}{res}      8,526        0.27        7.58
{txt}          1 {c |}{res}    197,104        6.21       13.79
{txt}          2 {c |}{res}    803,430       25.30       39.08
{txt}          3 {c |}{res}    432,057       13.60       52.69
{txt}          4 {c |}{res}    256,992        8.09       60.78
{txt}          5 {c |}{res}    612,036       19.27       80.05
{txt}          6 {c |}{res}     17,072        0.54       80.59
{txt}          7 {c |}{res}    247,323        7.79       88.37
{txt}          8 {c |}{res}    220,820        6.95       95.33
{txt}          9 {c |}{res}    148,467        4.67      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,176,150      100.00
{txt}(3,629,398 missing values generated)
(3,629,398 missing values generated)
(3,629,398 missing values generated)
(3,629,398 missing values generated)
(3,629,398 missing values generated)
(3,629,398 missing values generated)
(3,629,398 missing values generated)
(3,629,398 missing values generated)
(3,629,398 missing values generated)
(3,629,398 missing values generated)
(3,629,398 missing values generated)
(232,323 real changes made)
(8,526 real changes made)
(197,104 real changes made)
(803,430 real changes made)
(432,057 real changes made)
(256,992 real changes made)
(612,036 real changes made)
(17,072 real changes made)
(247,323 real changes made)
(220,820 real changes made)
(148,467 real changes made)
(1,637,613 missing values generated)
(2,012,895 missing values generated)
(3,809,338 missing values generated)
(3,813,505 missing values generated)
(1,371,196 missing values generated)
(1,725,361 missing values generated)
(1,542,272 missing values generated)
(1,865,969 missing values generated)
(1,570,036 missing values generated)
(1,881,052 missing values generated)
(1,568,260 missing values generated)
(1,890,970 missing values generated)
(1,860,889 missing values generated)
(2,172,628 missing values generated)
(3,731,636 missing values generated)
(3,748,657 missing values generated)
(2,838,745 missing values generated)
(2,973,257 missing values generated)
(2,945,568 missing values generated)
(3,077,206 missing values generated)
(2,455,149 missing values generated)
(2,697,977 missing values generated)
(3,852,892 missing values generated)
(139,436 real changes made)
(8,147 real changes made)
(156,473 real changes made)
(690,399 real changes made)
(371,710 real changes made)
(207,698 real changes made)
(497,632 real changes made)
(13,652 real changes made)
(210,883 real changes made)
(177,629 real changes made)
(88,039 real changes made)
(3,852,892 missing values generated)
(175,376 real changes made)
(8,254 real changes made)
(182,565 real changes made)
(700,715 real changes made)
(388,139 real changes made)
(226,971 real changes made)
(508,333 real changes made)
(14,958 real changes made)
(216,530 real changes made)
(181,740 real changes made)
(96,148 real changes made)
(232,323 real changes made)
(8,526 real changes made)
(197,104 real changes made)
(803,430 real changes made)
(432,057 real changes made)
(256,992 real changes made)
(612,036 real changes made)
(17,072 real changes made)
(247,323 real changes made)
(220,820 real changes made)
(148,467 real changes made)
(3,852,892 missing values generated)
(175,376 real changes made)
(8,254 real changes made)
(182,565 real changes made)
(700,715 real changes made)
(388,139 real changes made)
(226,971 real changes made)
(508,333 real changes made)
(14,958 real changes made)
(216,530 real changes made)
(181,740 real changes made)
(96,148 real changes made)
(1,238,644 missing values generated)
(139,436 real changes made, 139,436 to missing)
(164,628 real changes made, 164,628 to missing)
(2,215,893 missing values generated)
(2,215,892 missing values generated)
(2,426,350 missing values generated)
(2,638,856 missing values generated)
(2,458,370 missing values generated)
(3,035,727 missing values generated)
(2,532,604 missing values generated)
(2,532,603 missing values generated)
(2,670,061 missing values generated)
(2,862,933 missing values generated)
(3,276,487 missing values generated)
(4 real changes made, 4 to missing)
(3,804,976 missing values generated)
(3,807,663 missing values generated)
(3,819,613 missing values generated)
(3,704,391 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
(578,893 missing values generated)
AstSNI_str generated as {res:str5}
(578,893 missing values generated)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         932,539
{txt}{col 9}from master{col 30}{res}         932,538{txt}  (_merge==1)
{col 9}from using{col 30}{res}               1{txt}  (_merge==2)

{col 5}matched{col 30}{res}       2,920,354{txt}  (_merge==3)
{col 5}{hline 41}
{res}
      {txt}SSYK2 {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          . {c |}{res}     14,831        0.50        0.50
{txt}         01 {c |}{res}      8,526        0.29        0.79
{txt}         11 {c |}{res}      3,405        0.12        0.91
{txt}         12 {c |}{res}    160,952        5.47        6.38
{txt}         13 {c |}{res}     50,996        1.73        8.11
{txt}         21 {c |}{res}    161,826        5.50       13.61
{txt}         22 {c |}{res}     78,047        2.65       16.26
{txt}         23 {c |}{res}    178,682        6.07       22.33
{txt}         24 {c |}{res}    214,497        7.29       29.61
{txt}         31 {c |}{res}    134,717        4.58       34.19
{txt}         32 {c |}{res}    100,217        3.40       37.60
{txt}         33 {c |}{res}     81,122        2.76       40.35
{txt}         34 {c |}{res}    271,207        9.21       49.56
{txt}         41 {c |}{res}    229,761        7.81       57.37
{txt}         42 {c |}{res}     35,840        1.22       58.59
{txt}         51 {c |}{res}    438,063       14.88       73.47
{txt}         52 {c |}{res}    124,283        4.22       77.69
{txt}         61 {c |}{res}     17,072        0.58       78.27
{txt}         62 {c |}{res}          1        0.00       78.27
{txt}         71 {c |}{res}    140,252        4.76       83.03
{txt}         72 {c |}{res}     79,144        2.69       85.72
{txt}         73 {c |}{res}      4,105        0.14       85.86
{txt}         74 {c |}{res}      6,427        0.22       86.08
{txt}         81 {c |}{res}     44,475        1.51       87.59
{txt}         82 {c |}{res}    128,720        4.37       91.96
{txt}         83 {c |}{res}     91,808        3.12       95.08
{txt}         91 {c |}{res}    124,548        4.23       99.31
{txt}         92 {c |}{res}      1,665        0.06       99.37
{txt}         93 {c |}{res}     18,523        0.63      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  2,943,712      100.00
{txt}(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(3,659,129 missing values generated)
(14,831 real changes made)
(8,526 real changes made)
(3,405 real changes made)
(160,952 real changes made)
(50,996 real changes made)
(161,826 real changes made)
(78,047 real changes made)
(178,682 real changes made)
(214,497 real changes made)
(134,717 real changes made)
(100,217 real changes made)
(81,122 real changes made)
(271,207 real changes made)
(229,761 real changes made)
(35,840 real changes made)
(438,063 real changes made)
(124,283 real changes made)
(17,072 real changes made)
(1 real change made)
(140,252 real changes made)
(79,144 real changes made)
(4,105 real changes made)
(6,427 real changes made)
(44,475 real changes made)
(128,720 real changes made)
(91,808 real changes made)
(124,548 real changes made)
(1,665 real changes made)
(3,464,213 missing values generated)
(3,517,947 missing values generated)
(3,809,339 missing values generated)
(3,813,506 missing values generated)
(3,562,318 missing values generated)
(3,597,825 missing values generated)
(1,608,844 missing values generated)
(1,920,224 missing values generated)
(2,946,183 missing values generated)
(3,078,876 missing values generated)
(2,604,785 missing values generated)
(2,770,250 missing values generated)
(3,206,792 missing values generated)
(3,303,052 missing values generated)
(3,128,589 missing values generated)
(3,234,162 missing values generated)
(2,136,998 missing values generated)
(2,371,463 missing values generated)
(2,443,802 missing values generated)
(2,625,697 missing values generated)
(3,119,771 missing values generated)
(3,232,436 missing values generated)
(3,273,047 missing values generated)
(3,354,162 missing values generated)
(1,930,800 missing values generated)
(2,193,051 missing values generated)
(1,626,409 missing values generated)
(1,938,676 missing values generated)
(3,110,515 missing values generated)
(3,217,406 missing values generated)
(2,342,312 missing values generated)
(2,597,099 missing values generated)
(3,423,441 missing values generated)
(3,476,727 missing values generated)
(3,731,637 missing values generated)
(3,748,658 missing values generated)
(3,852,893 missing values generated)
(3,852,893 missing values generated)
(2,820,476 missing values generated)
(2,959,102 missing values generated)
(3,231,744 missing values generated)
(3,314,777 missing values generated)
(3,756,627 missing values generated)
(3,772,306 missing values generated)
(3,801,568 missing values generated)
(3,810,575 missing values generated)
(3,435,270 missing values generated)
(3,485,859 missing values generated)
(3,379,114 missing values generated)
(3,451,072 missing values generated)
(3,347,839 missing values generated)
(3,425,876 missing values generated)
(2,571,894 missing values generated)
(2,797,756 missing values generated)
(3,841,221 missing values generated)
(3,843,130 missing values generated)
(3,852,893 missing values generated)
(11,702 real changes made)
(8,147 real changes made)
(1,987 real changes made)
(127,972 real changes made)
(31,983 real changes made)
(136,120 real changes made)
(59,296 real changes made)
(149,677 real changes made)
(185,093 real changes made)
(114,187 real changes made)
(85,090 real changes made)
(71,612 real changes made)
(231,745 real changes made)
(183,944 real changes made)
(28,005 real changes made)
(344,834 real changes made)
(108,078 real changes made)
(13,652 real changes made)
(0 real changes made)
(119,029 real changes made)
(67,267 real changes made)
(3,331 real changes made)
(4,155 real changes made)
(39,295 real changes made)
(101,381 real changes made)
(71,904 real changes made)
(69,990 real changes made)
(961 real changes made)
(3,852,893 missing values generated)
(13,313 real changes made)
(8,254 real changes made)
(3,238 real changes made)
(149,093 real changes made)
(46,838 real changes made)
(140,229 real changes made)
(61,858 real changes made)
(151,492 real changes made)
(193,924 real changes made)
(120,946 real changes made)
(87,690 real changes made)
(73,650 real changes made)
(245,822 real changes made)
(202,709 real changes made)
(31,744 real changes made)
(351,244 real changes made)
(112,268 real changes made)
(14,958 real changes made)
(0 real changes made)
(125,508 real changes made)
(70,294 real changes made)
(3,729 real changes made)
(4,536 real changes made)
(40,074 real changes made)
(103,281 real changes made)
(74,710 real changes made)
(77,035 real changes made)
(1,131 real changes made)
(14,831 real changes made)
(8,526 real changes made)
(3,405 real changes made)
(160,952 real changes made)
(50,996 real changes made)
(161,826 real changes made)
(78,047 real changes made)
(178,682 real changes made)
(214,497 real changes made)
(134,717 real changes made)
(100,217 real changes made)
(81,122 real changes made)
(271,207 real changes made)
(229,761 real changes made)
(35,840 real changes made)
(438,063 real changes made)
(124,283 real changes made)
(17,072 real changes made)
(1 real change made)
(140,252 real changes made)
(79,144 real changes made)
(4,105 real changes made)
(6,427 real changes made)
(44,475 real changes made)
(128,720 real changes made)
(91,808 real changes made)
(124,548 real changes made)
(1,665 real changes made)
(3,852,893 missing values generated)
(13,313 real changes made)
(8,254 real changes made)
(3,238 real changes made)
(149,093 real changes made)
(46,838 real changes made)
(140,229 real changes made)
(61,858 real changes made)
(151,492 real changes made)
(193,924 real changes made)
(120,946 real changes made)
(87,690 real changes made)
(73,650 real changes made)
(245,822 real changes made)
(202,709 real changes made)
(31,744 real changes made)
(351,244 real changes made)
(112,268 real changes made)
(14,958 real changes made)
(0 real changes made)
(125,508 real changes made)
(70,294 real changes made)
(3,729 real changes made)
(4,536 real changes made)
(40,074 real changes made)
(103,281 real changes made)
(74,710 real changes made)
(77,035 real changes made)
(1,131 real changes made)
(1,404,849 missing values generated)
(21,836 real changes made, 21,836 to missing)
(0 real changes made)
(24,755 real changes made, 24,755 to missing)
(0 real changes made)
(3,614,711 missing values generated)
(3,659,997 missing values generated)
(2,676,217 missing values generated)
(2,957,861 missing values generated)
(3,637,613 missing values generated)
(3,680,090 missing values generated)
(2,726,032 missing values generated)
(3,019,236 missing values generated)
(3,616,160 missing values generated)
(3,641,625 missing values generated)
(2,979,109 missing values generated)
(3,080,142 missing values generated)
(2,514,342 missing values generated)
(2,842,843 missing values generated)
(2,496,450 missing values generated)
(2,786,047 missing values generated)
(578,894 missing values generated)
file E:\ProjData\IntegrationSD\temp\workplace_2014.dta saved

{com}. 
. 
. 
. 
. ///FOR ROBUSTNESS, CREATE A BASELINE MEASURE WITH NO RESTRICTIONS ON SAMPLE
> *WORKPLACE DATA FOR 2006, 2010 AND 2014
. forvalues y = 2006(4)2014 {c -(}
{txt}  2{com}. 
. use "E:\ProjData\IntegrationSD\temp\LISA`y'.dta"
{txt}  3{com}. 
. *STILL HAS TO DROP THIS
. drop if ArbstId==.
{txt}  4{com}. 
. ///throw out duplicates
> duplicates tag LopNr, gen(tag)
{txt}  5{com}. tab tag
{txt}  6{com}. drop if tag==1
{txt}  7{com}. *2006: none
. *2010: 2 ind/4 obs deleted*
. *2014: 2 ind/4 obs deleted*
. drop tag
{txt}  8{com}. 
. 
. ///ADD Birth country data, need to define foreign born/non-European
> merge 1:1 LopNr using "RTB\FodelselandIFAUGrupp"
{txt}  9{com}.         keep if _merge==3 
{txt} 10{com}.         drop _merge
{txt} 11{com}.         
. 
. ////////////////////////////////////////////
> ////NOW THE FOLLOWING LINE OF CODES CREATES 
> ///THE MAIN TREATMENT; SHARE OF IM 
> //// COWORKERS AMONG SWEDED
> ////////////////////////////////////////////    
> 
. 
. ///Start by defining being a native or comming from certain region, used to 
> *consider type of coworker
. gen swedish = 1 if IFAUkod==0
{txt} 12{com}. gen other =  1 if IFAUkod >39 & IFAUkod < 54
{txt} 13{com}. 
. ///Now workplace codes, by workplace (ArbstId) , to gen # im coworkers vs # coworkers per workplace
> *all immigrant workers at a workplace
. bysort ArbstId: egen im_coworker = total(other)
{txt} 14{com}. *all workers at a workplace
. bysort ArbstId: gen coworkers = _N
{txt} 15{com}. 
. ///now condition the created workplace variables on being swedish
> *this creates the main treatment variable, share of (im)coworkers if you are Swedish
. foreach x in im  {c -(}
{txt} 16{com}. gen `x'_coworker_swe = `x'_coworker if IFAUkod==0
{txt} 17{com}. {c )-}
{txt} 18{com}. 
. *Total coworkers if you are swedish
. gen coworkers_swe = coworkers if IFAUkod==0
{txt} 19{com}. 
. *to create "CO"-workers, rather than workers, take coworkers - oneself; 
. * "coworkers" otherwise captures all workers
. gen cw_not_i = coworkers-1
{txt} 20{com}. gen sh_im_cw_noi = im_coworker/cw_not_i
{txt} 21{com}. gen sh_im_cw_noi_swe_rob = sh_im_cw_noi if IFAUkod==0
{txt} 22{com}. 
. 
. ///keep
> keep LopNr sh_im_cw_noi_swe_rob 
{txt} 23{com}.  
. ///Left with: 
> ///check amount of workplaces
> *bysort ArbstId: gen diff_jobs = _n
. *count if diff_jobs==1
. *2006: 3,604,076 workers connected to a workplace id 192,088 workplaces
. *2010: 3,684,633 workers connected to a workplace id 203,576 workplaces
. *2014: 3,852,892 workers connected to a workplace id 211,953 workplaces
. 
. save "E:\ProjData\IntegrationSD\temp\workplace_`y'_rob.dta", replace
{txt} 24{com}. 
. erase "E:\ProjData\IntegrationSD\temp\LISA`y'.dta"
{txt} 25{com}. {c )-}
{txt}(3,372,043 observations deleted)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

        {txt}tag {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          0 {c |}{res}  4,060,969      100.00      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  4,060,969      100.00
{txt}(0 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}      12,011,278
{txt}{col 9}from master{col 30}{res}             136{txt}  (_merge==1)
{col 9}from using{col 30}{res}      12,011,142{txt}  (_merge==2)

{col 5}matched{col 30}{res}       4,060,833{txt}  (_merge==3)
{col 5}{hline 41}
(12,011,278 observations deleted)
(466,341 missing values generated)
(3,878,300 missing values generated)
(466,341 missing values generated)
(466,341 missing values generated)
(268,882 missing values generated)
(700,671 missing values generated)
file E:\ProjData\IntegrationSD\temp\workplace_2006_rob.dta saved
(3,674,662 observations deleted)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

        {txt}tag {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          0 {c |}{res}  4,175,945      100.00      100.00
{txt}          1 {c |}{res}          4        0.00      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  4,175,949      100.00
{txt}(4 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}      11,896,176
{txt}{col 9}from master{col 30}{res}              73{txt}  (_merge==1)
{col 9}from using{col 30}{res}      11,896,103{txt}  (_merge==2)

{col 5}matched{col 30}{res}       4,175,872{txt}  (_merge==3)
{col 5}{hline 41}
(11,896,176 observations deleted)
(544,432 missing values generated)
(3,937,843 missing values generated)
(544,432 missing values generated)
(544,432 missing values generated)
(297,325 missing values generated)
(799,063 missing values generated)
file E:\ProjData\IntegrationSD\temp\workplace_2010_rob.dta saved
(3,656,751 observations deleted)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

        {txt}tag {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          0 {c |}{res}  4,408,567      100.00      100.00
{txt}          1 {c |}{res}          4        0.00      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  4,408,571      100.00
{txt}(4 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}      11,663,632
{txt}{col 9}from master{col 30}{res}             112{txt}  (_merge==1)
{col 9}from using{col 30}{res}      11,663,520{txt}  (_merge==2)

{col 5}matched{col 30}{res}       4,408,455{txt}  (_merge==3)
{col 5}{hline 41}
(11,663,632 observations deleted)
(664,600 missing values generated)
(4,092,672 missing values generated)
(664,600 missing values generated)
(664,600 missing values generated)
(356,616 missing values generated)
(969,352 missing values generated)
file E:\ProjData\IntegrationSD\temp\workplace_2014_rob.dta saved

{com}. 
. 
{txt}end of do-file

{com}. 
. 
. ///4. Merge individual data on demographics and socioeconomics with individual level
> * workplace data from (3.) and election results from (1.), collapse everything on
. * precinct level  
. *Also prepares information for labor market regions used as control
. 
. do "C:\Userdata\Shared\Dofiles\DoData\IntegrationSD\management_inddata_collapse"
{txt}
{com}. ***********************************************************************
. * Authors: Henrik Andersson & Sirus Dehdari
. * This do-file merges workplace information at individual level, individual
. * info on socioeconomics and demographics, elections results and 
. * collpses all on precinct level for each year 2006, 2010 and 2014
. * It also adds info on labor maarket regions used for control.  
. *********************************************************************
. 
. clear all
{res}{txt}
{com}. 
. cd "D:\SCB_ConPol\Stata"
{res}D:\SCB_ConPol\Stata
{txt}
{com}. set more off
{txt}
{com}. 
. use "RTB\RTB_2006" 
{txt}
{com}. 
. 
. duplicates drop LopNr, force /* 6 obs*/

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(6 observations deleted)

{com}. 
. ///merge on some birth data
> merge 1:m LopNr using "RTB\Fodelseuppg"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       6,961,334
{txt}{col 9}from master{col 30}{res}             193{txt}  (_merge==1)
{col 9}from using{col 30}{res}       6,961,141{txt}  (_merge==2)

{col 5}matched{col 30}{res}       9,111,479{txt}  (_merge==3)
{col 5}{hline 41}

{com}. 
. ///keep only those living in the country in 2010
>         keep if _merge==3
{txt}(6,961,334 observations deleted)

{com}.         drop _merge
{txt}
{com}.         duplicates drop LopNr, force /*1 obs*/

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(1 observation deleted)

{com}. 
. gen year=2006
{txt}
{com}. 
. tostring FodArMan, replace
{txt}FodArMan was {res:long} now {res:str6}

{com}. gen year_born = substr(FodArMan, 1, 4) 
{txt}
{com}. destring year_born, replace
{txt}year_born: all characters numeric; {res}replaced {txt}as {res}int
{txt}
{com}. 
. gen month_born = substr(FodArMan, 5, 2)
{txt}
{com}. destring month_born, replace
{txt}month_born: all characters numeric; {res}replaced {txt}as {res}byte
{txt}
{com}. 
. gen age =year-year_born
{txt}
{com}. 
.         drop if age<18
{txt}(1,933,478 observations deleted)

{com}.         
. 
. ///Birth country data
> merge 1:1 LopNr using "RTB\FodelselandIFAUGrupp"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       8,894,245
{txt}{col 9}from master{col 30}{res}             135{txt}  (_merge==1)
{col 9}from using{col 30}{res}       8,894,110{txt}  (_merge==2)

{col 5}matched{col 30}{res}       7,177,865{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if _merge==3 
{txt}(8,894,245 observations deleted)

{com}.         drop _merge
{txt}
{com}. 
. ///LISA - use year before
> merge 1:m LopNr using "LISA\LISA_2005"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         318,591
{txt}{col 9}from master{col 30}{res}          70,301{txt}  (_merge==1)
{col 9}from using{col 30}{res}         248,290{txt}  (_merge==2)

{col 5}matched{col 30}{res}       7,107,568{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if _merge==3 
{txt}(318,591 observations deleted)

{com}.         drop _merge
{txt}
{com}. 
. duplicates drop LopNr, force /*4 obs*/

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(4 observations deleted)

{com}. 
. ///Workplace data
> gen sample=1
{txt}
{com}. drop ArbstId Sektorkod
{txt}
{com}. merge 1:1 LopNr using "E:\ProjData\IntegrationSD\temp\workplace_2006.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       3,543,875
{txt}{col 9}from master{col 30}{res}       3,523,681{txt}  (_merge==1)
{col 9}from using{col 30}{res}          20,194{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,583,883{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if sample==1
{txt}(20,194 observations deleted)

{com}.         drop _merge sample
{txt}
{com}.         
.         ///Workplace data adding the robust version of share of foreign born
> gen sample=1
{txt}
{com}. merge 1:1 LopNr using "E:\ProjData\IntegrationSD\temp\workplace_2006_rob.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       3,090,191
{txt}{col 9}from master{col 30}{res}       3,068,461{txt}  (_merge==1)
{col 9}from using{col 30}{res}          21,730{txt}  (_merge==2)

{col 5}matched{col 30}{res}       4,039,103{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if sample==1
{txt}(21,730 observations deleted)

{com}.         drop _merge sample
{txt}
{com}. 
.         ///Valdeltagardata
> 
. merge 1:1 LopNr using "E:\ProjData\IntegrationSD\temp\2006_electiondistrictsperperson.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         272,223
{txt}{col 9}from master{col 30}{res}          78,504{txt}  (_merge==1)
{col 9}from using{col 30}{res}         193,719{txt}  (_merge==2)

{col 5}matched{col 30}{res}       7,029,060{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if _merge==3
{txt}(272,223 observations deleted)

{com}.         drop _merge 
{txt}
{com}.         rename llkkdddd llkkdddd_new
{res}{txt}
{com}. 
.         ///Valdeltagardata 02
>                 gen sample=1
{txt}
{com}. merge 1:1 LopNr using "E:\ProjData\IntegrationSD\temp\2002_electiondistrictsperperson.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,124,328
{txt}{col 9}from master{col 30}{res}         554,125{txt}  (_merge==1)
{col 9}from using{col 30}{res}         570,203{txt}  (_merge==2)

{col 5}matched{col 30}{res}       6,474,935{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if sample==1
{txt}(570,203 observations deleted)

{com}.         drop _merge sample
{txt}
{com}. 
.         gen share_im_cworker_swe_stayed =  share_im_cworker_swe if llkkdddd== llkkdddd_new
{txt}(5,216,399 missing values generated)

{com}.         gen im_coworker_swe_stayed = im_coworker_swe if llkkdddd== llkkdddd_new
{txt}(5,216,399 missing values generated)

{com}.         gen sh_im_cw_noi_swe_stay = sh_im_cw_noi_swe if llkkdddd== llkkdddd_new
{txt}(5,216,399 missing values generated)

{com}.         gen coworkers_swe_stayed = coworkers_swe if llkkdddd== llkkdddd_new
{txt}(5,216,399 missing values generated)

{com}.         gen inflow = 1 if llkkdddd!= llkkdddd_new
{txt}(4,153,651 missing values generated)

{com}.         gen inflow_swe = 1 if llkkdddd!= llkkdddd_new & IFAUkod==0
{txt}(4,629,673 missing values generated)

{com}.         drop llkkdddd
{txt}
{com}. rename llkkdddd_new llkkdddd
{res}{txt}
{com}. 
. ///migration date
> merge 1:m LopNr using "RTB\Migrationer"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       9,117,482
{txt}{col 9}from master{col 30}{res}       5,844,554{txt}  (_merge==1)
{col 9}from using{col 30}{res}       3,272,928{txt}  (_merge==2)

{col 5}matched{col 30}{res}       1,728,214{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _merge
{txt}
{com}. *drop those not in the country 2006
. drop if Kommun==.
{txt}(3,272,928 observations deleted)

{com}. 
. *Eliminate duplicates
. 
. *keep first immigration year
. sort LopNr Datum 
{txt}
{com}. bysort LopNr: gen n=_n
{txt}
{com}. 
. duplicates tag LopNr, gen(circleim)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}
{txt}
{com}. tab PostTyp, gen(im_em)

{txt}Record type {c |}
 of input / {c |}
 emigration {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
        Inv {c |}{res}  1,270,655       73.52       73.52
{txt}        Utv {c |}{res}    457,559       26.48      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  1,728,214      100.00
{txt}
{com}. 
.         keep if im_em1==. /*not imm.*/ | (im_em1==1 & n==1) /*first immigration date*/ | (im_em1==1 & n==2) /*first immigration date if first date registeterd is emigration date*/
{txt}(579,945 observations deleted)

{com}. 
.         ///left with a number of people who for some reasons imigrated twise without emigrating
>         *duplicates report LopNr
.         drop circleim
{txt}
{com}.         duplicates tag LopNr, gen(circleim)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}
{txt}
{com}.         sort  circleim LopNr
{txt}
{com}.         drop if n==2
{txt}(229,012 observations deleted)

{com}. 
.         tostring Datum, replace
{txt}Datum was {res:long} now {res:str8}

{com}. gen im_year = substr(Datum, 1, 4) 
{txt}
{com}. destring im_year, replace
{txt}im_year: all characters numeric; {res}replaced {txt}as {res}int
{txt}(5844554 missing values generated)
{res}{txt}
{com}. 
. 
. ///PREPARE DATA TO COLLAPSE
> gen pop =1 
{txt}
{com}. replace Kon=. if Kon==2
{txt}(3,443,294 real changes made, 3,443,294 to missing)

{com}. rename Kon men
{res}{txt}
{com}. 
. gen young = 1 if age<31
{txt}(5,497,422 missing values generated)

{com}. 
. 
. gen swedish = 1 if IFAUkod==0
{txt}(934,081 missing values generated)

{com}. gen nordic = 1 if IFAUkod==26 | IFAUkod==27 | IFAUkod==28
{txt}(6,519,099 missing values generated)

{com}. gen western = 1 if IFAUkod == 32 | IFAUkod == 33 | IFAUkod == 34 | IFAUkod == 38 | IFAUkod == 39
{txt}(6,660,424 missing values generated)

{com}. gen europe_other = 1 if IFAUkod == 29 | IFAUkod == 30 | IFAUkod == 31 | IFAUkod == 35 | IFAUkod == 36 | IFAUkod == 37
{txt}(6,535,045 missing values generated)

{com}. gen other =  1 if IFAUkod >39 & IFAUkod < 54
{txt}(6,406,713 missing values generated)

{com}. 
. *Married
. 
. encode Civil, gen(civil)  
{txt}
{com}. gen married = 1 if civil==2 | civil==4
{txt}(3,814,137 missing values generated)

{com}. 
. tostring CivDat, replace
{txt}CivDat was {res:long} now {res:str8}

{com}. gen year_marr = substr(CivDat, 1, 4) 
{txt}
{com}. destring year_marr, replace
{txt}year_marr: all characters numeric; {res}replaced {txt}as {res}int
{txt}(4 missing values generated)
{res}{txt}
{com}. 
. gen new_married = 1 if married ==1 & year_marr==2006
{txt}(6,679,585 missing values generated)

{com}. 
. gen divorced = 1 if civil==5
{txt}(5,954,944 missing values generated)

{com}. gen new_divorce = 1 if divorced ==1 & year_marr==2006
{txt}(6,728,418 missing values generated)

{com}. 
. 
. *Parent
. gen parent =1 if Barn0_3>0 | Barn4_6>0 | Barn7_10>0 | Barn11_15> 0 | Barn16_17>0
{txt}(4,697,144 missing values generated)

{com}. 
. encode Sun2000niva_old, gen(Sun2000niva_old_dstr)
{txt}
{com}. gen high_educ = 1 if Sun2000niva_old_dstr>5
{txt}(4,903,211 missing values generated)

{com}. gen low_educ = 1 if Sun2000niva_old_dstr==1 | Sun2000niva_old_dstr==2
{txt}(5,702,673 missing values generated)

{com}. 
. 
. *Using Yrkstalln
. gen employed = 1 if Yrkstalln==2
{txt}(2,485,856 missing values generated)

{com}. gen employed_nordic = 1 if Yrkstalln==2 & nordic == 1
{txt}(6,641,465 missing values generated)

{com}. gen employed_swedish = 1 if Yrkstalln==2 & swedish == 1
{txt}(2,987,820 missing values generated)

{com}. gen employed_western = 1 if Yrkstalln==2 & western == 1
{txt}(6,712,517 missing values generated)

{com}. gen employed_europeother = 1 if Yrkstalln==2 & europe_other == 1
{txt}(6,636,512 missing values generated)

{com}. gen employed_other = 1 if Yrkstalln==2 & other == 1
{txt}(6,562,847 missing values generated)

{com}. 
. *self-employed
. gen se = 1 if Yrkstalln==4 | Yrkstalln==5
{txt}(6,272,457 missing values generated)

{com}. gen se_nordic = 1 if (Yrkstalln==4 | Yrkstalln==5)  & nordic == 1
{txt}(6,751,703 missing values generated)

{com}. gen se_swedish = 1 if (Yrkstalln==4 | Yrkstalln==5) & swedish == 1
{txt}(6,322,995 missing values generated)

{com}. gen se_western = 1 if (Yrkstalln==4 | Yrkstalln==5) & western == 1
{txt}(6,755,960 missing values generated)

{com}. gen se_europeother = 1 if (Yrkstalln==4 | Yrkstalln==5) & europe_other == 1
{txt}(6,754,484 missing values generated)

{com}. gen se_other = 1 if (Yrkstalln==4 | Yrkstalln==5) & other == 1
{txt}(6,742,560 missing values generated)

{com}. 
. *unemployed
. gen unemployed = 1 if Yrkstalln==0
{txt}(4,777,783 missing values generated)

{com}. gen unemployed_nordic = 1 if Yrkstalln==0 & nordic == 1
{txt}(6,654,088 missing values generated)

{com}. gen unemployed_swedish = 1 if Yrkstalln==0 & swedish == 1
{txt}(5,158,014 missing values generated)

{com}. gen unemployed_western = 1 if Yrkstalln==0 & western == 1
{txt}(6,719,718 missing values generated)

{com}. gen unemployed_europeother = 1 if Yrkstalln==0 & europe_other == 1
{txt}(6,671,973 missing values generated)

{com}. gen unemployed_other = 1 if Yrkstalln==0 & other == 1
{txt}(6,629,290 missing values generated)

{com}. 
. *Skill composition of non-European immigrants
. gen other_high_educ = 1 if other ==  1 & high_educ == 1 
{txt}(6,663,629 missing values generated)

{com}. gen other_low_educ = 1 if other ==  1 & low_educ == 1 
{txt}(6,695,172 missing values generated)

{com}. 
. 
. *Citizens: 
. encode Medblandnamn, gen(medb)
{txt}
{com}. gen ctz = 1 if medb==10 /*Sweden is 10*/
{txt}(285,053 missing values generated)

{com}. gen ctz_other = 1 if medb==10 & other==1
{txt}(6,473,740 missing values generated)

{com}. *new citizens
. tostring MedBdat, gen(date_ctz)
{txt}date_ctz generated as {res:str8}

{com}. gen year_ctz = substr(date_ctz, 1, 4) 
{txt}
{com}. destring year_ctz, replace
{txt}year_ctz: all characters numeric; {res}replaced {txt}as {res}int
{txt}(18 missing values generated)
{res}{txt}
{com}. gen new_ctz = 1 if year_ctz==2006 & ctz==1 & UtlSvBakG==11
{txt}(6,730,453 missing values generated)

{com}. gen im = 1 if UtlSvBakG==11
{txt}(5,829,734 missing values generated)

{com}. 
. ///high and low skilled use first digit in SSYK
> capture gen SSKY_str = substr(SSYK3, 1,1)
{txt}
{com}. capture gen SSKY_str = substr(ssyk3_2012, 1,1)
{txt}
{com}. encode SSKY_str, gen(SSKY1)
{txt}
{com}. gen high_skilled_nh=1 if SSKY1==1 | SSKY1==2 | SSKY1==3
{txt}(4,783,171 missing values generated)

{com}. gen low_skilled_nh =1 if SSKY1>3 & SSKY1!=. 
{txt}(1,980,640 missing values generated)

{com}. 
. 
. *Just to count the actual used number of individuals
. preserve
{txt}
{com}. gen S=1
{txt}
{com}. keep LopNr S
{txt}
{com}. save  "E:\ProjData\IntegrationSD\temp\2006_sampleofind.dta", replace
{txt}file E:\ProjData\IntegrationSD\temp\2006_sampleofind.dta saved

{com}. restore 
{txt}
{com}. 
. ///collapse
> 
. collapse (count) pop young men swedish im nordic western europe_other other married parent ///
> high_educ low_educ ctz ctz_other unemployed unemployed_nordic unemployed_swedish ///
> unemployed_western unemployed_europeother unemployed_other other_high_educ ///
> other_low_educ workers workers_swe inflow inflow_swe divorced new_divorce ///
> employed employed_nordic employed_swedish employed_western employed_europeother /// 
> employed_other se se_nordic se_swedish se_western se_europeother se_other /// 
> highsk_other lowsk_other high_skilled low_skilled high_skilled_nh low_skilled_nh new_ctz new_married ///
> (mean) LoneInk DispInk04 ALosDag SocBidrPersF04 im_coworker coworkers  ///
> share_im_cworker share_im_cworker_swe im_coworker_swe deviation_sector ///
> share_im_cworker_swe_stayed share_matched_swe_smwp share_matched_swe_bigwp ///
> im_coworker_swe_stayed coworkers_swe_stayed coworkers_swe ///
> latin_coworker mena_coworker asia_coworker africa_coworker rest_coworker nordic_coworker western_coworker ///
> share_latin_cworker share_latin_cworker_swe latin_coworker_swe share_mena_cworker /// 
> share_mena_cworker_swe mena_coworker_swe share_asia_cworker share_asia_cworker_swe ///
> asia_coworker_swe share_africa_cworker share_africa_cworker_swe africa_coworker_swe ///
> share_rest_cworker share_rest_cworker_swe rest_coworker_swe share_nordic_cworker ///
> share_nordic_cworker_swe nordic_coworker_swe share_western_cworker ///
> share_western_cworker_swe western_coworker_swe yearincountry  ///
> newim_coworker mediumnewim_coworker notnewim_coworker oldim_coworker /// 
> share_newim_cworker share_newim_cworker_swe newim_coworker_swe ///
> share_mediumnewim_cworker share_mediumnewim_cworker_swe mediumnewim_coworker_swe ///
> share_notnewim_cworker share_notnewim_cworker_swe notnewim_coworker_swe ///
> share_oldim_cworker share_oldim_cworker_swe oldim_coworker_swe ///
> highsk_coworker lowsk_coworker highskother_coworker lowskother_coworker  ///
> share_highsk_cworker share_highsk_cworker_swe highsk_coworker_swe share_lowsk_cworker ///
> share_lowsk_cworker_swe lowsk_coworker_swe share_highskother_cworker share_highskother_cworker_swe ///
> highskother_coworker_swe share_lowskother_cworker share_lowskother_cworker_swe ///
> sector_share_im lowskother_coworker_swe matchedcoworkers share_matchedhigh_cworker ///
> share_matchedlow_cworker sharecrossskill_highnative sharecrossskill_lownative crossskill ///
> matchedcoworkers_all share_matchedhigh_allcworker share_matchedlow_allcworker ///
> share_im_cworker_swe_smwp share_im_cworker_swe_bigwp share_cross_bigwp share_cross_smallwp ///
> share_young_cw_wp share_male_cw_wp wage_cw_wp share_ssyk2 ///
> share_ssyk2_topRTI share_ssyk2_bottomRTI share_ssyk2_midbottomRTI ///
> share_non_ssyk2 share_ssyk2_midtopRTI share_ssyk2_big stdRTI ///
>  share_ssyk2_small share_non_ssyk2_big share_non_ssyk2_small matchedcw ///
> sh_im_cw_noi_swe_stay sh_im_cw_noi_swe share_topRTI share_ssyk1 share_non_ssyk1 ///
> share_midtopRTI share_midbottomRTI share_bottomRTI ///
>  share_matched_big share_matched_small share_cross_big share_cross_small share_matched_topRTI ///
>  share_cross_topRTI share_matched_bottomRTI share_cross_bottomRTI sh_im_cw_noi_swe_rob , by(llkkdddd)
{txt}
{com}.  
. rename other other_im  
{res}{txt}
{com}.  
.         ///Valresultat-data
> 
. *merge 1:1 llkkdddd using "D:\Data\ProjData\IntegrationSD\temp\2006_electionresults.dta"
. *keep if _merge==3 
.         *drop _merge 
.         
. save "E:\ProjData\IntegrationSD\temp\2006.dta", replace
{txt}file E:\ProjData\IntegrationSD\temp\2006.dta saved

{com}. 
.         
. ********
. * 2010 *
. ********
. 
. clear all
{res}{txt}
{com}. 
. cd "D:\SCB_ConPol\Stata"
{res}D:\SCB_ConPol\Stata
{txt}
{com}. 
. use "RTB\RTB_2010" 
{txt}
{com}. 
. 
. duplicates drop LopNr, force /* 44 obs*/

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(44 observations deleted)

{com}. 
. ///merge on some birth data
> merge 1:m LopNr using "RTB\Fodelseuppg"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       6,657,095
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}       6,657,095{txt}  (_merge==2)

{col 5}matched{col 30}{res}       9,415,525{txt}  (_merge==3)
{col 5}{hline 41}

{com}. 
. ///keep only those living in the country in 2010
>         keep if _merge==3
{txt}(6,657,095 observations deleted)

{com}.         drop _merge
{txt}
{com}.         duplicates drop LopNr, force /*1 obs*/

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(1 observation deleted)

{com}. 
. gen year=2010
{txt}
{com}. 
. tostring FodArMan, replace
{txt}FodArMan was {res:long} now {res:str6}

{com}. gen year_born = substr(FodArMan, 1, 4) 
{txt}
{com}. destring year_born, replace
{txt}year_born: all characters numeric; {res}replaced {txt}as {res}int
{txt}
{com}. 
. gen month_born = substr(FodArMan, 5, 2)
{txt}
{com}. destring month_born, replace
{txt}month_born: all characters numeric; {res}replaced {txt}as {res}byte
{txt}
{com}. 
. gen age =year-year_born
{txt}
{com}. 
.         drop if age<18
{txt}(1,919,088 observations deleted)

{com}. ///Birth country data
> merge 1:1 LopNr using "RTB\FodelselandIFAUGrupp"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       8,575,985
{txt}{col 9}from master{col 30}{res}             223{txt}  (_merge==1)
{col 9}from using{col 30}{res}       8,575,762{txt}  (_merge==2)

{col 5}matched{col 30}{res}       7,496,213{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if _merge==3 /*1 ind dropped*/
{txt}(8,575,985 observations deleted)

{com}.         drop _merge
{txt}
{com}. 
. ///LISA - use year before
> merge 1:m LopNr using "LISA\LISA_2009"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         325,774
{txt}{col 9}from master{col 30}{res}          74,666{txt}  (_merge==1)
{col 9}from using{col 30}{res}         251,108{txt}  (_merge==2)

{col 5}matched{col 30}{res}       7,421,571{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if _merge==3 
{txt}(325,774 observations deleted)

{com}.         drop _merge
{txt}
{com}. 
. duplicates drop LopNr, force /*24 obs*/

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(24 observations deleted)

{com}. 
. ///Workplace data
> gen sample=1
{txt}
{com}. drop ArbstId Sektorkod
{txt}
{com}. merge 1:1 LopNr using "E:\ProjData\IntegrationSD\temp\workplace_2010.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       3,778,267
{txt}{col 9}from master{col 30}{res}       3,757,590{txt}  (_merge==1)
{col 9}from using{col 30}{res}          20,677{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,663,957{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if sample==1
{txt}(20,677 observations deleted)

{com}.         drop _merge sample
{txt}
{com}.         
.         
.                 ///Workplace data adding the robust version of share of foreign born
> gen sample=1
{txt}
{com}. merge 1:1 LopNr using "E:\ProjData\IntegrationSD\temp\workplace_2010_rob.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       3,290,813
{txt}{col 9}from master{col 30}{res}       3,268,244{txt}  (_merge==1)
{col 9}from using{col 30}{res}          22,569{txt}  (_merge==2)

{col 5}matched{col 30}{res}       4,153,303{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if sample==1
{txt}(22,569 observations deleted)

{com}.         drop _merge sample
{txt}
{com}.         
.         ///Valdeltagardata
> 
. merge 1:1 LopNr using "E:\ProjData\IntegrationSD\temp\2010_electiondistrictsperperson.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         332,594
{txt}{col 9}from master{col 30}{res}         118,946{txt}  (_merge==1)
{col 9}from using{col 30}{res}         213,648{txt}  (_merge==2)

{col 5}matched{col 30}{res}       7,302,601{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if _merge==3
{txt}(332,594 observations deleted)

{com}.         drop _merge 
{txt}
{com}.         
.                 rename llkkdddd llkkdddd_new
{res}{txt}
{com}. 
.         ///Valdeltagardata 06
>                 gen sample=1
{txt}
{com}. merge 1:1 LopNr using "E:\ProjData\IntegrationSD\temp\2006_electiondistrictsperperson.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,282,048
{txt}{col 9}from master{col 30}{res}         680,935{txt}  (_merge==1)
{col 9}from using{col 30}{res}         601,113{txt}  (_merge==2)

{col 5}matched{col 30}{res}       6,621,666{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if sample==1
{txt}(601,113 observations deleted)

{com}.         drop _merge sample
{txt}
{com}. 
.         gen share_im_cworker_swe_stayed =  share_im_cworker_swe if llkkdddd== llkkdddd_new
{txt}(5,636,298 missing values generated)

{com}.         gen im_coworker_swe_stayed = im_coworker_swe if llkkdddd== llkkdddd_new
{txt}(5,636,298 missing values generated)

{com}.                 gen sh_im_cw_noi_swe_stay = sh_im_cw_noi_swe if llkkdddd== llkkdddd_new
{txt}(5,636,298 missing values generated)

{com}.         gen coworkers_swe_stayed = coworkers_swe if llkkdddd== llkkdddd_new
{txt}(5,636,298 missing values generated)

{com}.         gen inflow = 1 if llkkdddd!= llkkdddd_new
{txt}(3,883,076 missing values generated)

{com}.         gen inflow_swe = 1 if llkkdddd!= llkkdddd_new & IFAUkod==0
{txt}(4,525,604 missing values generated)

{com}.         drop llkkdddd
{txt}
{com}. rename llkkdddd_new llkkdddd
{res}{txt}
{com}. 
. ///migration date
> merge 1:m LopNr using "RTB\Migrationer"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       9,065,458
{txt}{col 9}from master{col 30}{res}       5,964,454{txt}  (_merge==1)
{col 9}from using{col 30}{res}       3,101,004{txt}  (_merge==2)

{col 5}matched{col 30}{res}       1,900,138{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _merge
{txt}
{com}. *drop those not in the country 2010
. drop if Kommun==.
{txt}(3,101,004 observations deleted)

{com}. 
. *Eliminate duplicates
. 
. *keep first immigration year
. sort LopNr Datum 
{txt}
{com}. bysort LopNr: gen n=_n
{txt}
{com}. 
. duplicates tag LopNr, gen(circleim)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}
{txt}
{com}. tab PostTyp, gen(im_em)

{txt}Record type {c |}
 of input / {c |}
 emigration {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
        Inv {c |}{res}  1,440,617       75.82       75.82
{txt}        Utv {c |}{res}    459,521       24.18      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  1,900,138      100.00
{txt}
{com}. 
.         keep if im_em1==. /*not imm.*/ | (im_em1==1 & n==1) /*first immigration date*/ | (im_em1==1 & n==2) /*first immigration date if first date registeterd is emigration date*/
{txt}(587,726 observations deleted)

{com}. 
.         ///left with a number of people who for some reasons imigrated twise without emigrating
>         *duplicates report LopNr
.         drop circleim
{txt}
{com}.         duplicates tag LopNr, gen(circleim)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}
{txt}
{com}.         sort  circleim LopNr
{txt}
{com}.         drop if n==2
{txt}(239,488 observations deleted)

{com}. 
.         tostring Datum, replace
{txt}Datum was {res:long} now {res:str8}

{com}. gen im_year = substr(Datum, 1, 4) 
{txt}
{com}. destring im_year, replace
{txt}im_year: all characters numeric; {res}replaced {txt}as {res}int
{txt}(5964454 missing values generated)
{res}{txt}
{com}. 
. 
. ///PREPARE DATA TO COLLAPSE
> gen pop =1 
{txt}
{com}. replace Kon=. if Kon==2
{txt}(3,563,525 real changes made, 3,563,525 to missing)

{com}. rename Kon men
{res}{txt}
{com}. 
. gen young = 1 if age<31
{txt}(5,622,377 missing values generated)

{com}. 
. gen swedish = 1 if IFAUkod==0
{txt}(1,083,392 missing values generated)

{com}. gen nordic = 1 if IFAUkod==26 | IFAUkod==27 | IFAUkod==28
{txt}(6,801,532 missing values generated)

{com}. gen western = 1 if IFAUkod == 32 | IFAUkod == 33 | IFAUkod == 34 | IFAUkod == 38 | IFAUkod == 39
{txt}(6,920,427 missing values generated)

{com}. gen europe_other = 1 if IFAUkod == 29 | IFAUkod == 30 | IFAUkod == 31 | IFAUkod == 35 | IFAUkod == 36 | IFAUkod == 37
{txt}(6,752,246 missing values generated)

{com}. gen other =  1 if IFAUkod >39 & IFAUkod < 54
{txt}(6,592,104 missing values generated)

{com}. 
. 
. *Married
. 
. encode Civil, gen(civil)  
{txt}
{com}. gen married = 1 if civil==2 | civil==4
{txt}(4,027,422 missing values generated)

{com}. 
. tostring CivDat, replace
{txt}CivDat was {res:long} now {res:str8}

{com}. gen year_marr = substr(CivDat, 1, 4) 
{txt}
{com}. destring year_marr, replace
{txt}year_marr: all characters numeric; {res}replaced {txt}as {res}int
{txt}
{com}. 
. gen new_married = 1 if married ==1 & year_marr==2010
{txt}(6,943,877 missing values generated)

{com}. gen divorced = 1 if civil==5
{txt}(6,192,560 missing values generated)

{com}. gen new_divorce = 1 if divorced ==1 & year_marr==2010
{txt}(6,996,745 missing values generated)

{com}. 
. 
. *parent
. gen parent =1 if Barn0_3>0 | Barn4_6>0 | Barn7_10>0 | Barn11_15> 0 | Barn16_17>0
{txt}(4,920,717 missing values generated)

{com}. 
. *educ
. encode Sun2000niva_old, gen(Sun2000niva_old_dstr)
{txt}
{com}. gen high_educ = 1 if Sun2000niva_old_dstr>5
{txt}(4,940,645 missing values generated)

{com}. gen low_educ = 1 if Sun2000niva_old_dstr==1 | Sun2000niva_old_dstr==2
{txt}(6,116,831 missing values generated)

{com}. 
. 
. *Using Yrkstalln
. gen employed = 1 if Yrkstalln==2
{txt}(2,622,349 missing values generated)

{com}. gen employed_nordic = 1 if Yrkstalln==2 & nordic == 1
{txt}(6,927,451 missing values generated)

{com}. gen employed_swedish = 1 if Yrkstalln==2 & swedish == 1
{txt}(3,203,904 missing values generated)

{com}. gen employed_western = 1 if Yrkstalln==2 & western == 1
{txt}(6,980,082 missing values generated)

{com}. gen employed_europeother = 1 if Yrkstalln==2 & europe_other == 1
{txt}(6,878,347 missing values generated)

{com}. gen employed_other = 1 if Yrkstalln==2 & other == 1
{txt}(6,782,158 missing values generated)

{com}. 
. *self-employed
. gen se = 1 if Yrkstalln==4 | Yrkstalln==5
{txt}(6,519,244 missing values generated)

{com}. gen se_nordic = 1 if (Yrkstalln==4 | Yrkstalln==5)  & nordic == 1
{txt}(7,024,854 missing values generated)

{com}. gen se_swedish = 1 if (Yrkstalln==4 | Yrkstalln==5) & swedish == 1
{txt}(6,580,416 missing values generated)

{com}. gen se_western = 1 if (Yrkstalln==4 | Yrkstalln==5) & western == 1
{txt}(7,028,339 missing values generated)

{com}. gen se_europeother = 1 if (Yrkstalln==4 | Yrkstalln==5) & europe_other == 1
{txt}(7,024,234 missing values generated)

{com}. gen se_other = 1 if (Yrkstalln==4 | Yrkstalln==5) & other == 1
{txt}(7,010,919 missing values generated)

{com}. 
. *unemployed
. gen unemployed = 1 if Yrkstalln==0
{txt}(4,941,621 missing values generated)

{com}. gen unemployed_nordic = 1 if Yrkstalln==0 & nordic == 1
{txt}(6,924,503 missing values generated)

{com}. gen unemployed_swedish = 1 if Yrkstalln==0 & swedish == 1
{txt}(5,380,980 missing values generated)

{com}. gen unemployed_western = 1 if Yrkstalln==0 & western == 1
{txt}(6,986,890 missing values generated)

{com}. gen unemployed_europeother = 1 if Yrkstalln==0 & europe_other == 1
{txt}(6,924,708 missing values generated)

{com}. gen unemployed_other = 1 if Yrkstalln==0 & other == 1
{txt}(6,874,154 missing values generated)

{com}. 
. *Skill composition of non-European immigrants
. gen other_high_educ = 1 if other ==  1 & high_educ == 1 
{txt}(6,897,724 missing values generated)

{com}. gen other_low_educ = 1 if other ==  1 & low_educ == 1 
{txt}(6,951,547 missing values generated)

{com}. 
. *Citizens: 
. encode Medblandnamn, gen(medb)
{txt}
{com}. gen ctz = 1 if medb==10 /*Sweden is 10*/
{txt}(354,359 missing values generated)

{com}. gen ctz_other = 1 if medb==10 & other==1
{txt}(6,689,720 missing values generated)

{com}. 
. *new citizens
. tostring MedBdat, gen(date_ctz)
{txt}date_ctz generated as {res:str8}

{com}. gen year_ctz = substr(date_ctz, 1, 4) 
{txt}
{com}. destring year_ctz, replace
{txt}year_ctz: all characters numeric; {res}replaced {txt}as {res}int
{txt}(10 missing values generated)
{res}{txt}
{com}. gen new_ctz = 1 if year_ctz==2010 & ctz==1 & UtlSvBakG==11
{txt}(7,015,918 missing values generated)

{com}. gen im = 1 if UtlSvBakG==11
{txt}(5,953,991 missing values generated)

{com}. 
. 
. ///high and low skilled use first digit in SSYK
> capture gen SSKY_str = substr(SSYK3, 1,1)
{txt}
{com}. capture gen SSKY_str = substr(ssyk3_2012, 1,1)
{txt}
{com}. encode SSKY_str, gen(SSKY1)
{txt}
{com}. gen high_skilled_nh=1 if SSKY1==1 | SSKY1==2 | SSKY1==3
{txt}(5,237,613 missing values generated)

{com}. gen low_skilled_nh =1 if SSKY1>3 & SSKY1!=. 
{txt}(1,799,765 missing values generated)

{com}. 
. preserve
{txt}
{com}. gen S=1
{txt}
{com}. keep LopNr S
{txt}
{com}. save  "E:\ProjData\IntegrationSD\temp\2010_sampleofind.dta", replace
{txt}file E:\ProjData\IntegrationSD\temp\2010_sampleofind.dta saved

{com}. restore 
{txt}
{com}. ///collapse
> 
. 
. collapse (count) pop young men swedish im nordic western europe_other other married parent ///
> high_educ low_educ ctz ctz_other unemployed unemployed_nordic unemployed_swedish ///
> unemployed_western unemployed_europeother unemployed_other other_high_educ ///
> other_low_educ workers workers_swe inflow inflow_swe divorced new_divorce ///
> employed employed_nordic employed_swedish employed_western employed_europeother /// 
> employed_other se se_nordic se_swedish se_western se_europeother se_other /// 
> highsk_other lowsk_other high_skilled low_skilled high_skilled_nh low_skilled_nh new_ctz new_married ///
> (mean) LoneInk DispInk04 ALosDag SocBidrPersF04 im_coworker coworkers  ///
> share_im_cworker share_im_cworker_swe im_coworker_swe deviation_sector ///
> share_im_cworker_swe_stayed share_matched_swe_smwp share_matched_swe_bigwp ///
> im_coworker_swe_stayed coworkers_swe_stayed coworkers_swe ///
> latin_coworker mena_coworker asia_coworker africa_coworker rest_coworker nordic_coworker western_coworker ///
> share_latin_cworker share_latin_cworker_swe latin_coworker_swe share_mena_cworker /// 
> share_mena_cworker_swe mena_coworker_swe share_asia_cworker share_asia_cworker_swe ///
> asia_coworker_swe share_africa_cworker share_africa_cworker_swe africa_coworker_swe ///
> share_rest_cworker share_rest_cworker_swe rest_coworker_swe share_nordic_cworker ///
> share_nordic_cworker_swe nordic_coworker_swe share_western_cworker ///
> share_western_cworker_swe western_coworker_swe yearincountry  ///
> newim_coworker mediumnewim_coworker notnewim_coworker oldim_coworker /// 
> share_newim_cworker share_newim_cworker_swe newim_coworker_swe ///
> share_mediumnewim_cworker share_mediumnewim_cworker_swe mediumnewim_coworker_swe ///
> share_notnewim_cworker share_notnewim_cworker_swe notnewim_coworker_swe ///
> share_oldim_cworker share_oldim_cworker_swe oldim_coworker_swe ///
> highsk_coworker lowsk_coworker highskother_coworker lowskother_coworker  ///
> share_highsk_cworker share_highsk_cworker_swe highsk_coworker_swe share_lowsk_cworker ///
> share_lowsk_cworker_swe lowsk_coworker_swe share_highskother_cworker share_highskother_cworker_swe ///
> highskother_coworker_swe share_lowskother_cworker share_lowskother_cworker_swe ///
> sector_share_im lowskother_coworker_swe matchedcoworkers share_matchedhigh_cworker ///
> share_matchedlow_cworker sharecrossskill_highnative sharecrossskill_lownative crossskill ///
> matchedcoworkers_all share_matchedhigh_allcworker share_matchedlow_allcworker ///
> share_im_cworker_swe_smwp share_im_cworker_swe_bigwp share_cross_bigwp share_cross_smallwp ///
> share_young_cw_wp share_male_cw_wp wage_cw_wp share_ssyk2 ///
> share_ssyk2_topRTI share_ssyk2_bottomRTI share_ssyk2_midbottomRTI ///
> share_non_ssyk2 share_ssyk2_midtopRTI share_ssyk2_big stdRTI ///
>  share_ssyk2_small share_non_ssyk2_big share_non_ssyk2_small matchedcw ///
> sh_im_cw_noi_swe_stay sh_im_cw_noi_swe share_topRTI share_ssyk1 share_non_ssyk1 ///
> share_midtopRTI share_midbottomRTI share_bottomRTI ///
>  share_matched_big share_matched_small share_cross_big share_cross_small share_matched_topRTI ///
>  share_cross_topRTI share_matched_bottomRTI share_cross_bottomRTI sh_im_cw_noi_swe_rob , by(llkkdddd)
{txt}
{com}.  
.  rename other other_im  
{res}{txt}
{com}.  
.         ///Valresultat-data
> 
. *merge 1:1 llkkdddd using "D:\Data\ProjData\IntegrationSD\temp\2010_electionresults.dta"
. *keep if _merge==3 /*Why are some lost in the process?*/
.         *drop _merge 
.         
. save "E:\ProjData\IntegrationSD\temp\2010.dta", replace
{txt}file E:\ProjData\IntegrationSD\temp\2010.dta saved

{com}. 
. 
. ********
. * 2014 *
. ********
. 
. clear all
{res}{txt}
{com}. 
. cd "D:\SCB_ConPol\Stata"
{res}D:\SCB_ConPol\Stata
{txt}
{com}. 
. use "RTB\RTB_2014" 
{txt}
{com}. 
. 
. duplicates drop LopNr, force /* 13 obs*/

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(13 observations deleted)

{com}. 
. ///merge on some birth data
> merge 1:m LopNr using "RTB\Fodelseuppg"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       6,325,278
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}       6,325,278{txt}  (_merge==2)

{col 5}matched{col 30}{res}       9,747,342{txt}  (_merge==3)
{col 5}{hline 41}

{com}. 
. ///keep only those living in the country in 2014
>         keep if _merge==3
{txt}(6,325,278 observations deleted)

{com}.         drop _merge
{txt}
{com}.         duplicates drop LopNr, force /*1 obs*/

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(1 observation deleted)

{com}. 
. gen year=2014
{txt}
{com}. 
. tostring FodArMan, replace
{txt}FodArMan was {res:long} now {res:str6}

{com}. gen year_born = substr(FodArMan, 1, 4) 
{txt}
{com}. destring year_born, replace
{txt}year_born: all characters numeric; {res}replaced {txt}as {res}int
{txt}
{com}. 
. gen month_born = substr(FodArMan, 5, 2)
{txt}
{com}. destring month_born, replace
{txt}month_born: all characters numeric; {res}replaced {txt}as {res}byte
{txt}
{com}. 
. gen age =year-year_born
{txt}
{com}. 
.         drop if age<18
{txt}(1,985,284 observations deleted)

{com}.         
. ///Birth country data
> merge 1:1 LopNr using "RTB\FodelselandIFAUGrupp"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       8,310,692
{txt}{col 9}from master{col 30}{res}             387{txt}  (_merge==1)
{col 9}from using{col 30}{res}       8,310,305{txt}  (_merge==2)

{col 5}matched{col 30}{res}       7,761,670{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if _merge==3 
{txt}(8,310,692 observations deleted)

{com}.         drop _merge
{txt}
{com}. 
.         
. ///LISA - use year before
> merge 1:m LopNr using "LISA\LISA_2013"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         417,716
{txt}{col 9}from master{col 30}{res}          90,324{txt}  (_merge==1)
{col 9}from using{col 30}{res}         327,392{txt}  (_merge==2)

{col 5}matched{col 30}{res}       7,671,371{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if _merge==3 
{txt}(417,716 observations deleted)

{com}.         drop _merge
{txt}
{com}. 
. duplicates drop LopNr, force /*25 obs*/

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}

{txt}(25 observations deleted)

{com}. 
. ///Workplace data
> gen sample=1
{txt}
{com}. drop ArbstId Sektorkod
{txt}
{com}. merge 1:1 LopNr using "E:\ProjData\IntegrationSD\temp\workplace_2014.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       3,865,223
{txt}{col 9}from master{col 30}{res}       3,841,838{txt}  (_merge==1)
{col 9}from using{col 30}{res}          23,385{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,829,508{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if sample==1
{txt}(23,385 observations deleted)

{com}.         drop _merge sample
{txt}
{com}.         
.                         ///Workplace data adding the robust version of share of foreign born
> gen sample=1
{txt}
{com}. merge 1:1 LopNr using "E:\ProjData\IntegrationSD\temp\workplace_2014_rob.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       3,313,503
{txt}{col 9}from master{col 30}{res}       3,288,197{txt}  (_merge==1)
{col 9}from using{col 30}{res}          25,306{txt}  (_merge==2)

{col 5}matched{col 30}{res}       4,383,149{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if sample==1
{txt}(25,306 observations deleted)

{com}.         drop _merge sample
{txt}
{com}.         
.         ///Valdeltagardata
> 
. merge 1:1 LopNr using "E:\ProjData\IntegrationSD\temp\2014_electiondistrictsperperson.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         353,201
{txt}{col 9}from master{col 30}{res}         119,828{txt}  (_merge==1)
{col 9}from using{col 30}{res}         233,373{txt}  (_merge==2)

{col 5}matched{col 30}{res}       7,551,518{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if _merge==3
{txt}(353,201 observations deleted)

{com}.         drop _merge 
{txt}
{com}.         
.                 rename llkkdddd llkkdddd_new
{res}{txt}
{com}. 
.         ///Valdeltagardata 10
>                 gen sample=1
{txt}
{com}. merge 1:1 LopNr using "E:\ProjData\IntegrationSD\temp\2010_electiondistrictsperperson.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,282,309
{txt}{col 9}from master{col 30}{res}         658,789{txt}  (_merge==1)
{col 9}from using{col 30}{res}         623,520{txt}  (_merge==2)

{col 5}matched{col 30}{res}       6,892,729{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         keep if sample==1
{txt}(623,520 observations deleted)

{com}.         drop _merge sample
{txt}
{com}. 
.         gen share_im_cworker_swe_stayed =  share_im_cworker_swe if llkkdddd== llkkdddd_new
{txt}(5,752,750 missing values generated)

{com}.         gen im_coworker_swe_stayed = im_coworker_swe if llkkdddd== llkkdddd_new
{txt}(5,752,750 missing values generated)

{com}.                 gen sh_im_cw_noi_swe_stay = sh_im_cw_noi_swe if llkkdddd== llkkdddd_new
{txt}(5,752,750 missing values generated)

{com}.         gen coworkers_swe_stayed = coworkers_swe if llkkdddd== llkkdddd_new
{txt}(5,752,750 missing values generated)

{com}.         gen inflow = 1 if llkkdddd!= llkkdddd_new
{txt}(4,316,785 missing values generated)

{com}.         gen inflow_swe = 1 if llkkdddd!= llkkdddd_new & IFAUkod==0
{txt}(4,987,573 missing values generated)

{com}.         drop llkkdddd
{txt}
{com}. rename llkkdddd_new llkkdddd
{res}{txt}
{com}. 
. ///migration date
> merge 1:m LopNr using "RTB\Migrationer"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       9,001,628
{txt}{col 9}from master{col 30}{res}       6,053,667{txt}  (_merge==1)
{col 9}from using{col 30}{res}       2,947,961{txt}  (_merge==2)

{col 5}matched{col 30}{res}       2,053,181{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _merge
{txt}
{com}. *drop those not in the country 2014
. drop if Kommun==.
{txt}(2,947,961 observations deleted)

{com}. 
. *Eliminate duplicates
. 
. *keep first immigration year
. sort LopNr Datum 
{txt}
{com}. bysort LopNr: gen n=_n
{txt}
{com}. 
. duplicates tag LopNr, gen(circleim)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}
{txt}
{com}. tab PostTyp, gen(im_em)

{txt}Record type {c |}
 of input / {c |}
 emigration {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
        Inv {c |}{res}  1,631,358       79.46       79.46
{txt}        Utv {c |}{res}    421,823       20.54      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  2,053,181      100.00
{txt}
{com}. 
.         keep if im_em1==. /*not imm.*/ | (im_em1==1 & n==1) /*first immigration date*/ | (im_em1==1 & n==2) /*first immigration date if first date registeterd is emigration date*/
{txt}(558,670 observations deleted)

{com}. 
.         ///left with a number of people who for some reasons imigrated twise without emigrating
>         *duplicates report LopNr
.         drop circleim
{txt}
{com}.         duplicates tag LopNr, gen(circleim)

{p 0 4}{txt}Duplicates in terms of {res} LopNr{p_end}
{txt}
{com}.         sort  circleim LopNr
{txt}
{com}.         drop if n==2
{txt}(256,592 observations deleted)

{com}. 
.         tostring Datum, replace
{txt}Datum was {res:long} now {res:str8}

{com}. gen im_year = substr(Datum, 1, 4) 
{txt}
{com}. destring im_year, replace
{txt}im_year: all characters numeric; {res}replaced {txt}as {res}int
{txt}(6053667 missing values generated)
{res}{txt}
{com}. 
. 
. ///PREPARE DATA TO COLLAPSE
> gen pop =1 
{txt}
{com}. replace Kon=. if Kon==2
{txt}(3,679,122 real changes made, 3,679,122 to missing)

{com}. rename Kon men
{res}{txt}
{com}. 
. gen young = 1 if age<31
{txt}(5,780,120 missing values generated)

{com}. 
. gen swedish = 1 if IFAUkod==0
{txt}(1,245,603 missing values generated)

{com}. gen nordic = 1 if IFAUkod==26 | IFAUkod==27 | IFAUkod==28
{txt}(7,068,997 missing values generated)

{com}. gen western = 1 if IFAUkod == 32 | IFAUkod == 33 | IFAUkod == 34 | IFAUkod == 38 | IFAUkod == 39
{txt}(7,160,133 missing values generated)

{com}. gen europe_other = 1 if IFAUkod == 29 | IFAUkod == 30 | IFAUkod == 31 | IFAUkod == 35 | IFAUkod == 36 | IFAUkod == 37
{txt}(6,968,480 missing values generated)

{com}. gen other =  1 if IFAUkod >39 & IFAUkod < 54
{txt}(6,723,494 missing values generated)

{com}. 
. 
. *Married
. 
. encode Civil, gen(civil)  
{txt}
{com}. gen married = 1 if civil==2 | civil==4
{txt}(4,230,373 missing values generated)

{com}. 
. tostring CivDat, replace
{txt}CivDat was {res:long} now {res:str8}

{com}. gen year_marr = substr(CivDat, 1, 4) 
{txt}
{com}. destring year_marr, replace
{txt}year_marr: all characters numeric; {res}replaced {txt}as {res}int
{txt}
{com}. 
. gen new_married = 1 if married ==1 & year_marr==2014
{txt}(7,203,658 missing values generated)

{com}. gen divorced = 1 if civil==5
{txt}(6,394,646 missing values generated)

{com}. gen new_divorce = 1 if divorced ==1 & year_marr==2014
{txt}(7,249,076 missing values generated)

{com}. 
. *Parent
. gen parent =1 if Barn0_3>0 | Barn4_6>0 | Barn7_10>0 | Barn11_15> 0 | Barn16_17>0
{txt}(5,200,789 missing values generated)

{com}. 
. *Educ
. encode Sun2000niva_old, gen(Sun2000niva_old_dstr)
{txt}
{com}. gen high_educ = 1 if Sun2000niva_old_dstr>5
{txt}(4,906,976 missing values generated)

{com}. gen low_educ = 1 if Sun2000niva_old_dstr==1 | Sun2000niva_old_dstr==2
{txt}(6,497,796 missing values generated)

{com}. 
. 
. ///Using Yrkstalln
> gen employed = 1 if Yrkstalln==2
{txt}(2,663,259 missing values generated)

{com}. gen employed_nordic = 1 if Yrkstalln==2 & nordic == 1
{txt}(7,190,856 missing values generated)

{com}. gen employed_swedish = 1 if Yrkstalln==2 & swedish == 1
{txt}(3,359,941 missing values generated)

{com}. gen employed_western = 1 if Yrkstalln==2 & western == 1
{txt}(7,222,921 missing values generated)

{com}. gen employed_europeother = 1 if Yrkstalln==2 & europe_other == 1
{txt}(7,098,836 missing values generated)

{com}. gen employed_other = 1 if Yrkstalln==2 & other == 1
{txt}(6,957,235 missing values generated)

{com}. 
. *self-employed
. gen se = 1 if Yrkstalln==4 | Yrkstalln==5
{txt}(6,749,267 missing values generated)

{com}. gen se_nordic = 1 if (Yrkstalln==4 | Yrkstalln==5)  & nordic == 1
{txt}(7,279,246 missing values generated)

{com}. gen se_swedish = 1 if (Yrkstalln==4 | Yrkstalln==5) & swedish == 1
{txt}(6,820,543 missing values generated)

{com}. gen se_western = 1 if (Yrkstalln==4 | Yrkstalln==5) & western == 1
{txt}(7,281,735 missing values generated)

{com}. gen se_europeother = 1 if (Yrkstalln==4 | Yrkstalln==5) & europe_other == 1
{txt}(7,274,341 missing values generated)

{com}. gen se_other = 1 if (Yrkstalln==4 | Yrkstalln==5) & other == 1
{txt}(7,259,762 missing values generated)

{com}. 
. *unemployed
. gen unemployed = 1 if Yrkstalln==0
{txt}(5,177,567 missing values generated)

{com}. gen unemployed_nordic = 1 if Yrkstalln==0 & nordic == 1
{txt}(7,182,469 missing values generated)

{com}. gen unemployed_swedish = 1 if Yrkstalln==0 & swedish == 1
{txt}(5,654,155 missing values generated)

{com}. gen unemployed_western = 1 if Yrkstalln==0 & western == 1
{txt}(7,238,741 missing values generated)

{com}. gen unemployed_europeother = 1 if Yrkstalln==0 & europe_other == 1
{txt}(7,178,710 missing values generated)

{com}. gen unemployed_other = 1 if Yrkstalln==0 & other == 1
{txt}(7,089,996 missing values generated)

{com}. 
. 
. *Skill composition of non-European immigrants
. gen other_high_educ = 1 if other ==  1 & high_educ == 1 
{txt}(7,099,990 missing values generated)

{com}. gen other_low_educ = 1 if other ==  1 & low_educ == 1 
{txt}(7,180,986 missing values generated)

{com}. 
. *Citizens: 
. 
. encode Medblandnamn, gen(medb)
{txt}
{com}. gen ctz = 1 if medb==10 /*Sweden is 10*/
{txt}(409,357 missing values generated)

{com}. gen ctz_other = 1 if medb==10 & other==1
{txt}(6,860,577 missing values generated)

{com}. 
. *new citizens
. tostring MedBdat, gen(date_ctz)
{txt}date_ctz generated as {res:str8}

{com}. gen year_ctz = substr(date_ctz, 1, 4) 
{txt}
{com}. destring year_ctz, replace
{txt}year_ctz: all characters numeric; {res}replaced {txt}as {res}int
{txt}(11 missing values generated)
{res}{txt}
{com}. gen new_ctz = 1 if year_ctz==2014 & ctz==1 & UtlSvBakG==11
{txt}(7,262,306 missing values generated)

{com}. gen im = 1 if UtlSvBakG==11
{txt}(6,045,987 missing values generated)

{com}. 
. 
. ///high and low skilled use first digit in SSYK
> capture gen SSKY_str = substr(SSYK3, 1,1)
{txt}
{com}. capture gen SSKY_str = substr(ssyk3_2012, 1,1)
{txt}
{com}. encode SSKY_str, gen(SSKY1)
{txt}
{com}. gen high_skilled_nh=1 if SSKY1==1 | SSKY1==2 | SSKY1==3
{txt}(5,669,435 missing values generated)

{com}. gen low_skilled_nh =1 if SSKY1>3 & SSKY1!=. 
{txt}(1,622,151 missing values generated)

{com}. 
. 
. preserve
{txt}
{com}. gen S=1
{txt}
{com}. keep LopNr S
{txt}
{com}. save  "E:\ProjData\IntegrationSD\temp\2014_sampleofind.dta", replace
{txt}file E:\ProjData\IntegrationSD\temp\2014_sampleofind.dta saved

{com}. restore 
{txt}
{com}. ///collapse
> 
. 
. collapse (count) pop young men swedish im nordic western europe_other other married parent ///
> high_educ low_educ ctz ctz_other unemployed unemployed_nordic unemployed_swedish ///
> unemployed_western unemployed_europeother unemployed_other other_high_educ ///
> other_low_educ workers workers_swe inflow inflow_swe divorced new_divorce ///
> employed employed_nordic employed_swedish employed_western employed_europeother /// 
> employed_other se se_nordic se_swedish se_western se_europeother se_other /// 
> highsk_other lowsk_other high_skilled low_skilled high_skilled_nh low_skilled_nh new_ctz new_married ///
> (mean) LoneInk DispInk04 ALosDag SocBidrPersF04 im_coworker coworkers  ///
> share_im_cworker share_im_cworker_swe im_coworker_swe deviation_sector ///
> share_im_cworker_swe_stayed share_matched_swe_smwp share_matched_swe_bigwp ///
> im_coworker_swe_stayed coworkers_swe_stayed coworkers_swe ///
> latin_coworker mena_coworker asia_coworker africa_coworker rest_coworker nordic_coworker western_coworker ///
> share_latin_cworker share_latin_cworker_swe latin_coworker_swe share_mena_cworker /// 
> share_mena_cworker_swe mena_coworker_swe share_asia_cworker share_asia_cworker_swe ///
> asia_coworker_swe share_africa_cworker share_africa_cworker_swe africa_coworker_swe ///
> share_rest_cworker share_rest_cworker_swe rest_coworker_swe share_nordic_cworker ///
> share_nordic_cworker_swe nordic_coworker_swe share_western_cworker ///
> share_western_cworker_swe western_coworker_swe yearincountry  ///
> newim_coworker mediumnewim_coworker notnewim_coworker oldim_coworker /// 
> share_newim_cworker share_newim_cworker_swe newim_coworker_swe ///
> share_mediumnewim_cworker share_mediumnewim_cworker_swe mediumnewim_coworker_swe ///
> share_notnewim_cworker share_notnewim_cworker_swe notnewim_coworker_swe ///
> share_oldim_cworker share_oldim_cworker_swe oldim_coworker_swe ///
> highsk_coworker lowsk_coworker highskother_coworker lowskother_coworker  ///
> share_highsk_cworker share_highsk_cworker_swe highsk_coworker_swe share_lowsk_cworker ///
> share_lowsk_cworker_swe lowsk_coworker_swe share_highskother_cworker share_highskother_cworker_swe ///
> highskother_coworker_swe share_lowskother_cworker share_lowskother_cworker_swe ///
> sector_share_im lowskother_coworker_swe matchedcoworkers share_matchedhigh_cworker ///
> share_matchedlow_cworker sharecrossskill_highnative sharecrossskill_lownative crossskill ///
> matchedcoworkers_all share_matchedhigh_allcworker share_matchedlow_allcworker ///
> share_im_cworker_swe_smwp share_im_cworker_swe_bigwp share_cross_bigwp share_cross_smallwp ///
> share_young_cw_wp share_male_cw_wp wage_cw_wp share_ssyk2 ///
> share_ssyk2_topRTI share_ssyk2_bottomRTI share_ssyk2_midbottomRTI ///
> share_non_ssyk2 share_ssyk2_midtopRTI share_ssyk2_big stdRTI ///
>  share_ssyk2_small share_non_ssyk2_big share_non_ssyk2_small matchedcw ///
> sh_im_cw_noi_swe_stay sh_im_cw_noi_swe share_topRTI share_ssyk1 share_non_ssyk1 ///
> share_midtopRTI share_midbottomRTI share_bottomRTI ///
>  share_matched_big share_matched_small share_cross_big share_cross_small share_matched_topRTI ///
>  share_cross_topRTI share_matched_bottomRTI share_cross_bottomRTI sh_im_cw_noi_swe_rob , by(llkkdddd)
{txt}
{com}.  
.  rename other other_im  
{res}{txt}
{com}.  
.         ///Valresultat-data
> 
. gen str8 llkkdddd2 = string(llkkdddd,"%08.0f")
{txt}
{com}. drop llkkdddd
{txt}
{com}. rename llkkdddd2 llkkdddd
{res}{txt}
{com}. 
. merge 1:1 llkkdddd using "E:\ProjData\IntegrationSD\temp\2014_electionresults.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}           5,837{txt}  (_merge==3)
{col 5}{hline 41}

{com}. keep if _merge==3
{txt}(0 observations deleted)

{com}.         drop _merge 
{txt}
{com}.         
. save "E:\ProjData\IntegrationSD\temp\2014.dta", replace
{txt}file E:\ProjData\IntegrationSD\temp\2014.dta saved

{com}. 
. 
. 
. 
. ///Merge onto mapped files for the mapped districts
> 
. *2010-2014
. use "E:\ProjData\IntegrationSD\temp\2010.dta"
{txt}
{com}. gen str8 precinct2010 = string(llkkdddd,"%08.0f")
{txt}
{com}. drop llkkdddd
{txt}
{com}. *duplicates report lkfv
. 
. merge 1:m precinct2010 using "E:\ProjData\IntegrationSD\temp\vd_2010_2014_shares"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}           8,097{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _merge
{txt}
{com}. 
. order precinct2010 whole_pop precinct2014 totbef share
{txt}
{com}. save "E:\ProjData\IntegrationSD\temp\vd_2010_2014_shares_r", replace
{txt}file E:\ProjData\IntegrationSD\temp\vd_2010_2014_shares_r.dta saved

{com}. 
. 
. *2006-2014
. 
. use "E:\ProjData\IntegrationSD\temp\2006.dta"
{txt}
{com}. gen str8 precinct2006 = string(llkkdddd,"%08.0f")
{txt}
{com}. drop llkkdddd
{txt}
{com}. *duplicates report precinkt2006
. 
. merge 1:m precinct2006 using "E:\ProjData\IntegrationSD\temp\vd_2006_2014_shares"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}          21,867{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _merge
{txt}
{com}. 
. order precinct2006 whole_pop precinct2014 totbef share
{txt}
{com}. save "E:\ProjData\IntegrationSD\temp\vd_2006_2014_shares_r", replace
{txt}file E:\ProjData\IntegrationSD\temp\vd_2006_2014_shares_r.dta saved

{com}. 
. 
. *******************************
. * create labor market regions (used as control) *
. *******************************
. 
. clear all
{res}{txt}
{com}. 
. ///import info on labor market regions in Sweden 2014
> import excel "E:\ProjData\IntegrationSD\raw\Labor market regions 2014", firstrow 
{res}{txt}
{com}. 
. keep Kod namn kod 
{txt}
{com}. 
. rename kod kom_str
{res}{txt}
{com}. 
. drop if kom_str==.
{txt}(5 observations deleted)

{com}. save "E:\ProjData\IntegrationSD\temp\lmr2014", replace
{txt}file E:\ProjData\IntegrationSD\temp\lmr2014.dta saved

{com}. 
. 
. 
{txt}end of do-file

{com}. 
. 
. ///5. Use population weights from (2.) and collapse the precinct 
> * data created in (4.) to create comparable units over time. 
. * Merges everyhing to a final panel data file with information on many
. *precincts over three years (2006, 2010 and 2014).
. do "C:\Userdata\Shared\Dofiles\DoData\IntegrationSD\compute_shares"
{txt}
{com}. 
. ********************************************************************************
. * Authors: Henrik Andersson & Sirus Dehdari
. * Description: This script uses the precinct collapsed data for each election 
. * year and collapses it further in terms of 2010/2014 combinations
. * into 2014 precincts, using population weights for each combination.
. * It finally merges the collapsed data together into one panel file with many 
. * precinct information over three years, 2006, 2010 and 2014.  
. ********************************************************************************
. 
. clear all
{res}{txt}
{com}. cd "E:\"
{res}E:\
{txt}
{com}. 
. * Setting path to temp folder:
. local out_temp "E:\ProjData\IntegrationSD\temp\"
{txt}
{com}. 
. 
. 
. *** Henrik: här specificerar du namnet på den variabel som ligger allra sist i din variabellista.
. * Variabeln "pop" ligger ju först, så vi sparar en local med namnet på den som ligger sist
. local last_var = "sh_im_cw_noi_swe_rob"
{txt}
{com}. 
. 
. *** Cleaning 2010 election data (changing precinct code and variable name):
. use `out_temp'2010_electionresults, clear
{txt}
{com}. 
. * Adding "0" to districts where it has been dropped because of numeric:
. tostring llkkdddd, replace
{txt}llkkdddd was {res:long} now {res:str8}

{com}. replace llkkdddd = "0" + llkkdddd if strlen(llkkdddd) < 8
{txt}(2,315 real changes made)

{com}. rename llkkdddd precinct2010
{res}{txt}
{com}. 
. * Merging election data with the precinct combos:
. merge 1:m precinct2010 using `out_temp'\vd_2010_2014_shares_r
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}           8,097{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _merge
{txt}
{com}. 
. * Multiplying each election result (in numbers) with combo shares:
. foreach var of varlist *tal RostGiltiga Rostande Rostb other pop-`last_var'{c -(}
{txt}  2{com}. quietly replace `var' = share*`var'
{txt}  3{com}. {c )-}
{txt}
{com}. 
. * Aggregate to 2014 precints:
. collapse (sum) *tal RostGiltiga Rostande Rostb other pop-`last_var', by(precinct2014)
{txt}
{com}. 
. gen year = 2010
{txt}
{com}. 
. foreach var of varlist *tal{c -(}
{txt}  2{com}. local vname = substr("`var'", 1,strlen("`var'")-3)
{txt}  3{com}. gen `vname'proc = 100*`var'/(Mtal+Ctal+FPtal+KDtal+Stal+Vtal+MPtal+SDtal+FItal+PPtal+other)
{txt}  4{com}. {c )-}
{txt}
{com}. 
. * Create turnout variable:
. gen VD = 100*Rostande/Rostb
{txt}
{com}. 
. * Dropping all the number of votes variables (DO WE WANT TO KEEP THEM?)
. drop *tal
{txt}
{com}. 
. save `out_temp'reg_2010_2014, replace
{txt}file E:\ProjData\IntegrationSD\temp\reg_2010_2014.dta saved

{com}. 
. 
. 
. *************************
. *** 2006:
. import excel D:\Data\ExtData\ValResData\Riksdagsval_2006\Riksdagsval_2006.xls, sheet("riksdagsvalet_vd_2006_orginal") firstrow clear
{res}{txt}
{com}. 
. rename LKFV precinct2006
{res}{txt}
{com}. 
. merge 1:m precinct2006 using `out_temp'vd_2006_2014_shares_r, keep(3)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}          21,867{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _merge
{txt}
{com}. 
. foreach var of varlist *_ROST ROSTB pop-`last_var'{c -(}
{txt}  2{com}. quietly replace `var' = share*`var'
{txt}  3{com}. {c )-}
{txt}
{com}. 
. collapse (sum) *_ROST ROSTB pop- `last_var', by(precinct2014)
{txt}
{com}. 
. gen year = 2006
{txt}
{com}. 
. * Creating a "other parties" variable:
. gen other_ROST = SPI_ROST + JL_ROST + SJVP_ROST + ÖVR_ROST
{txt}
{com}. 
. drop SPI_ROST JL_ROST SJVP_ROST ÖVR_ROST
{txt}
{com}. 
. 
. foreach var of varlist *_ROST{c -(}
{txt}  2{com}. local vname = substr("`var'", 1,strlen("`var'")-5)
{txt}  3{com}. gen `vname'proc = 100*`var'/(M_ROST+C_ROST+FP_ROST+KD_ROST+S_ROST+V_ROST+MP_ROST+SD_ROST+FI_ROST+PP_ROST+other_ROST)
{txt}  4{com}. {c )-}
{txt}
{com}. 
. gen VD = 100*(M_ROST+C_ROST+FP_ROST+KD_ROST+S_ROST+V_ROST+MP_ROST+SD_ROST+FI_ROST+PP_ROST+other_ROST+BLANK_ROST)/ROSTB
{txt}
{com}. 
. * Dropping all the number of votes variables (DO WE WANT TO KEEP THEM?)
. drop *_ROST
{txt}
{com}. 
. 
. 
. save `out_temp'reg_2006_2014, replace
{txt}file E:\ProjData\IntegrationSD\temp\reg_2006_2014.dta saved

{com}. 
. 
. ///CREATE PANEL
> 
. ///Now put the 2010, 2006 and 2014 file together and prepare panel
> 
. clear all
{res}{txt}
{com}. use "E:\ProjData\IntegrationSD\temp\2014.dta"
{txt}
{com}. gen year=2014 
{txt}
{com}.  append using "E:\ProjData\IntegrationSD\temp\reg_2010_2014.dta"
{txt}{p 0 7 2}
(note: variable
Rostande was 
int, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
other was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
pop was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
young was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
men was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
swedish was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
im was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
nordic was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
western was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
europe_other was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
other_im was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
married was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
parent was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
high_educ was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
low_educ was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
ctz was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
ctz_other was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
unemployed was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
unemployed_nordic was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
unemployed_swedish was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
unemployed_western was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
unemployed_europeother was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
unemployed_other was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
other_high_educ was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
other_low_educ was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
workers was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
workers_swe was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
inflow was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
inflow_swe was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
divorced was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
new_divorce was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
employed was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
employed_nordic was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
employed_swedish was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
employed_western was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
employed_europeother was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
employed_other was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
se was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
se_nordic was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
se_swedish was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
se_western was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
se_europeother was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
se_other was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
highsk_other was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
lowsk_other was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
high_skilled was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
low_skilled was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
high_skilled_nh was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
low_skilled_nh was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
new_ctz was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
new_married was 
long, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
ALosDag was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
SocBidrPersF04 was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
im_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
coworkers was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_im_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_im_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
im_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
deviation_sector was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_im_cworker_swe_stayed was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_matched_swe_smwp was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_matched_swe_bigwp was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
im_coworker_swe_stayed was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
coworkers_swe_stayed was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
coworkers_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
latin_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
mena_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
asia_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
africa_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
rest_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
nordic_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
western_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_latin_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_latin_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
latin_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_mena_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_mena_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
mena_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_asia_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_asia_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
asia_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_africa_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_africa_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
africa_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_rest_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_rest_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
rest_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_nordic_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_nordic_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
nordic_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_western_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_western_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
western_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
yearincountry was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
newim_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
mediumnewim_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
notnewim_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
oldim_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_newim_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_newim_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
newim_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_mediumnewim_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_mediumnewim_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
mediumnewim_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_notnewim_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_notnewim_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
notnewim_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_oldim_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_oldim_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
oldim_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
highsk_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
lowsk_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
highskother_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
lowskother_coworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_highsk_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_highsk_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
highsk_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_lowsk_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_lowsk_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
lowsk_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_highskother_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_highskother_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
highskother_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_lowskother_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_lowskother_cworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
sector_share_im was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
lowskother_coworker_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
matchedcoworkers was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_matchedhigh_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_matchedlow_cworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
sharecrossskill_highnative was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
sharecrossskill_lownative was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
crossskill was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
matchedcoworkers_all was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_matchedhigh_allcworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_matchedlow_allcworker was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_im_cworker_swe_smwp was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_im_cworker_swe_bigwp was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_cross_bigwp was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_cross_smallwp was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_young_cw_wp was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_male_cw_wp was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
wage_cw_wp was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_ssyk2 was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_ssyk2_topRTI was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_ssyk2_bottomRTI was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_ssyk2_midbottomRTI was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_non_ssyk2 was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_ssyk2_midtopRTI was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_ssyk2_big was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
stdRTI was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_ssyk2_small was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_non_ssyk2_big was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_non_ssyk2_small was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
matchedcw was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
sh_im_cw_noi_swe_stay was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
sh_im_cw_noi_swe was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_topRTI was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_ssyk1 was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_non_ssyk1 was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_midtopRTI was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_midbottomRTI was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_bottomRTI was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_matched_big was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_matched_small was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_cross_big was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_cross_small was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_matched_topRTI was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_cross_topRTI was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_matched_bottomRTI was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
share_cross_bottomRTI was 
float, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
sh_im_cw_noi_swe_rob was 
float, now double to accommodate using data's values)
{p_end}

{com}.  replace year=2010 if year==.
{txt}(0 real changes made)

{com}.  replace precinct2014=llkkddd if year==2014
{txt}(5,837 real changes made)

{com}.  drop llkkdddd
{txt}
{com}.   append using "E:\ProjData\IntegrationSD\temp\reg_2006_2014.dta"
{txt}
{com}.   replace year=2006 if year==.
{txt}(0 real changes made)

{com}. 
.   *time variable
. gen t=1 if year==2006
{txt}(11,673 missing values generated)

{com}. replace t=2 if year==2010
{txt}(5,836 real changes made)

{com}. replace t=3 if year==2014
{txt}(5,837 real changes made)

{com}. 
. *panel setting
. order precinct2014 year t
{txt}
{com}. destring precinct2014, replace
{txt}precinct2014: all characters numeric; {res}replaced {txt}as {res}long
{txt}
{com}. xtset precinct2014 t
{res}{txt}{col 8}panel variable:  {res}precinct2014 (unbalanced)
{txt}{col 9}time variable:  {res}{col 25}t, 1 to 3, but with a gap
{txt}{col 17}delta:  {res}1 unit
{txt}
{com}. sort precinct2014 t
{txt}
{com}. 
. *duplicates tag precinct2014, gen(tag)
. *bysort year: tab tag
. *5,044 districts in 2010 and 2014 both years
. *4712 districts all years
. *272 enbart 2010
. *709 enbart 2006
. *659 enbart 2014
. save "E:\ProjData\IntegrationSD\use\main.dta", replace
{txt}file E:\ProjData\IntegrationSD\use\main.dta saved

{com}. 
. 
. 
. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}C:\Userdata\Shared\Logs\IntegrationSD\log_data.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res} 1 Jun 2021, 17:35:08
{txt}{.-}
{smcl}
{txt}{sf}{ul off}